Always lock your dependencies to a specific version.

Node Version Manager, or short nvm allows you to manage multiple node versions by installing them into your home folder. You can persist the current Node.js version into an .nvmrc by executing node -v > .nvmrc. Use nvm use to restore the Node.js version from the .nvmrc file. As mentioned, nvm stores the binaries and global packages into your home folder, like ~/.nvm/versions/node/v12.10.0/..., so when you switch the Node.js version you may need to reinstall the global packages.

  • To list installed global packages: npm list -g --depth 0
  • To upgrade nvm default to latest LTS, while keeping packages: nvm install lts/* --reinstall-packages-from=default
  • To install latest LTS: nvm install --lts or nvm install 'lts/*'
  • To set latest LTS as system default: nvm alias default 'lts/*'

If you use Docker of course you can lock the version in the Dockerfile, like FROM node:12.10.0.

Bonus tip: npm-check

npm-check checks for outdated dependencies.

Check for outdated local dependencies with npm-check -u, global with npm-check -gu