10 Tips and Tricks That Will Make You an npm Ninja
A few simple npm commands is all it takes to initialize a folder (npm init), download packages (npm install) and create tests (npm test) and custom scripts (npm run) for use in your project. Few delve further but there are several npm tips and tricks which can revolutionize your daily development tasks.
1. Getting Help!
Help for specific npm commands can also be displayed:
npm help <command>
npm help install.
Or you can view a quick command parameter reference:
npm <command> -h
2. npm Command Autocomplete
npm offers command auto-completion for systems using bash (including Bash for Windows 10):
npm completion >> ~/.bashrc
or Z shell:
npm completion >> ~/.zshrc
Reload the shell configuration file, e.g.
npm ins and hit TAB and
install will appear. You need never waste time typing in full ever again!
3. Fixing Global Module Permissions
Linux-like systems can throw permission errors when you attempt to install global packages. You can prepend
sudo to any npm command but that’s a dangerous option. A better solution is to change npm’s default directory to one you own:
mkdir ~/.npm-global npm config set prefix '~/.npm-global'
Add the following line to
~/.zshrc as appropriate using your text editor of choice:
Reload the shell configuration file (
source ~/.bashrc) then reinstall npm itself to the new user-owned location:
npm install -g npm
This will also update npm to the latest version.
Continue reading %10 Tips and Tricks That Will Make You an npm Ninja%