DEV Community

Guido Zambarda
Guido Zambarda

Posted on • Originally published at iamguidozam.blog on

Manage Node.js version for a project using NVM and .nvmrc file

I just discovered an interesting and useful feature of NVM so I decided to let everyone know about it!

If you don’t know NVM (Node Version Manager) you can read about it in my previous post here.

NVM lets you quickly switch the Node.js version for a project to a specific one. To do so you need to create a .nvmrc file which specify the version that you want to use.

To create the file go in the solution folder and execute the command:

node -v > .nvmrc
Enter fullscreen mode Exit fullscreen mode

This command will generate the file and write something like:

v16.20.2
Enter fullscreen mode Exit fullscreen mode

Once that you have your .nvmrc file created, the next time that you will have to put your hands on the project, you will have to simply run:

nvm use
Enter fullscreen mode Exit fullscreen mode

Doing so will change your current Node.js version to the one specified in the .nvmrc file.

NB : Unfortunately NVM for Windows does not support the use command (here’s the reason), in the eventuality that you’re on Windows I still suggest to create the .nvmrc file even if you cannot change the version with the use command, in this way you can always know which version of Node.js was used for the project.

Pretty neat trick to handle your Node.js version huh?

Hope this helps!

Top comments (0)