NPM is the node package manager that comes with node.js and you can use it right away after you have node installed.

NVM is used to manage your node versions. Don’t have nvm installed? Check out install guide or you can use my dotfiles to install and setup node version manager.

Listing globally installed NPM packages without dependencies

$ npm ls -g --depth=0

/Users/Marius/.nvm/versions/node/v5.11.0/lib
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
└── [email protected]

Instal new version of Node.js with NVM and make it default

In place of a version pointer like 6.0, you can use the following special default aliases with nvm install, nvm use, nvm run, nvm exec, nvm which, etc:

  • node: this installs the latest version of node
# this will install the latest node.js
nvm install node

# make and alias
nvm alias default node

# use the default version
nvm use default

If you set a default alias for specific version of nodejs than any new terminal window will use that nodejs version.

Migrate npm packages from a previous version of Node.js:

nvm install node --reinstall-packages-from=node

Change Node.js version with .nvmrc file

Create a .nvmrc file containing version number in the project root directory. Now you can use nvm use, nvm install, nvm exec, nvm run, and nvm which will all respect an .nvmrc file when a version is not supplied.

Run the following commands from your project root directory

# Create .nvmrc file with node version in it
echo "6.0" > .nvmrc

# Use this to change the version if you have it installed
nvm use

# Install the nodejs version from .nvmrc file
nvm install

Automatic change nodejs version when you cd in your project

AVN is Automatic Version Switching for Node.js. Now when you cd into a directory with a .node-version file, avn will automatically detect the change and use your installed version manager to switch to that version of node.