npm

Install Node

Install NodeJS by downloading the Mac installer.

# Check the Node version
node -v

Update Node

Warning: this can mess stuff up. Be careful.

sudo npm cache clean -f
sudo npm install -g n
sudo n stable

Reference

Initialize

Set up a brand new package.json file:

npm init

Install packages

Find packages on NPM JS.

Install all packages listed in package.json:

npm install

Install package in project (and save to package.json):

npm install --save-dev package-name

Install package globally (should only have to do this once):

sudo npm install -g package-name

Update packages

Check for outdated packages:

npm outdated

Update all packages in package.json:

npm update

# Make sure NPM cache is not holding old versions of packages
npm cache clean

Resources

Remove packages

Uninstall module locally (and remove from package.json):

npm uninstall package-name --save-dev

Remove packages not in package.json from /node_modules:

npm prune

Troubleshooting

When all packages are updated they might be incompatible, and require code changes.

Often enough the local files are just corrupt. Delete the entire node_modules folder, re-install, update, and clean cache.

rm -rf node_modules
npm install
npm update
npm cache clean

If something is still broken, and you can narrow it down to a specific package try uninstalling and re-installing it:

npm uninstall the-package-name
npm install the-package-name