Managing Node.js versions can be challenging when working on multiple projects with different requirements. Fortunately, there are several tools and techniques available that can help you manage Node.js versions based on project requirements.

Why Manage Node.js Versions?

One of the challenges of working with Node.js is managing the different versions of Node.js that are required for different projects. Different projects may have different dependencies, and these dependencies may require specific versions of Node.js.

If you’re not careful, you may end up with a mess of different Node.js versions on your system, which can cause conflicts and make it difficult to manage your projects effectively.

Techniques for Managing Node.js Versions

Current support policy

production applications should use a release currently listed as Active LTS or Maintenance LTS on the official Node.js release page. Pin the selected version for the project and use the same value in CI.

  1. Node Version Manager (nvm) Node Version Manager (nvm) is a command-line tool that allows you to manage multiple versions of Node.js on your system. With nvm, you can easily switch between different versions of Node.js and install new versions as needed.

Once you have nvm installed, you can use it to install and manage different versions of Node.js. For example, to install Node.js version lts, you can run the following command:

1
nvm install --lts

To switch to this version, you can run:

1
nvm use --lts

You can also use nvm to set a default Node.js version for a specific project by creating an .nvmrc file in the project directory. For example, to set the default version to 24, create an .nvmrc file with the following content:

1
24

Now, when you navigate to the project directory and run nvm use, it will automatically switch to version 24.

  1. Node.js Version Manager (n) Node.js Version Manager (n) is a simple command-line tool that allows you to install and switch between different versions of Node.js. It is similar to nvm but has a simpler and more streamlined interface.

To use n, you first need to install it on your system.

1
npm install -g n

Once you have n installed, you can use it to install and manage different versions of Node.js. For example, to install Node.js version 24, you can run the following command:

1
n 24

To switch to this version, you can run:

1
n lts

You can also use n to set a default Node.js version for a specific project by creating an .nvmrc file in the project directory, just like with nvm. For example, to set the default version to 24, create an .nvmrc file with the following content:

1
24