explorations in dev, science, sci-fi, games, and other fun stuff!

nvm/node: an easy way to use different versions for different projects

problem

I need to have different versions of node/npm for different projects. I’d prefer to have each project “know” which version of node/npm it needs to use.

solution

prerequisites

Before we get started, there are a few prerequisites:

understand that this is a Mac solution. While I’m sure a similar solution exists for Windows, I am neither knowledgeable enough nor inclined to write a compatible shell script for Windows at this time.

gameplan

leveraging .nvmrc

Much like Ruby has a shortcut for setting the current version of Ruby to use, nvm has a similar feature. When you enter the following command…

nvm use

… then nvm will look for a .nvmrc file and get the correct version number to use from there. So first navigate to a project folder that uses node and create a new file called .nvmrc. Inside just write 4.2. If you’re a command-line geek then do the following: