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

Published by

on

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

This command will generate the file and write something like:

v16.20.2

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

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!

One response to “Manage Node.js version for a project using NVM and .nvmrc file”

  1. […] Manage Node.js version for a project using NVM and .nvmrc file […]

    Like