DEV Community

Cover image for I’ve switched from NVM to Volta. This is Why
Pierre-Henry Soria ✨
Pierre-Henry Soria ✨

Posted on • Edited on

I’ve switched from NVM to Volta. This is Why

I've been using nvm for quite a long time to manage the different Node versions on my machine. nvm immediately remains me of the time when I was using RVM (Ruby Version Manager).

Apart from a great name and massive usage, nvm has some issues that can be easily fixed with a “more modern” alternative.

I’ve recently started using Volta and it does have many advantages in comparison with nvm.

volta pin node v14

First of all, it’s really fast (Volta claims to be ~40x faster than NVM). Switching to different versions or installing new Node/NPM versions has been a real pleasure. The startup time and project version switching are considerably fast.

Second, it always loads the correct Node version you need between your projects, whereas nvm doesn’t do it by default. With nvm, each time you switch to a different project that runs a different Node version than the default one, you need to either run nvm use <NODE_VERSION_NUMBER> or by locking a node version in a .nvmrc for each of your projects. Furthermore, you will still need to have a loaded script setup in your bash profile terminal that automatically searches for a .nvmrc and updates the node version when needed. In addition, there is always a delay when switching to another version with nvm (Volta switches the Node version instantly).

Volta (and a few others such as pnpm) does this under the hood. That way, when you are dealing with multiple repositories using different node versions, you won’t have any bad surprises of updating some dependencies with the wrong node version for instance.

For instance, volta pin node@14 will store your pinned version in your package.json of your project.

  "volta": {
    "node": "14.21.2"
 }
Enter fullscreen mode Exit fullscreen mode

Each time you go to one of your projects, Volta will read your package.json file and automatically and instantly set the relevant NodeJS version that reflects with what was pinned. You can also (and very easily) install a specific Node version with the following through Volta volta install node@16.

Volta also allows you to install and pin globally your favorite package manager. e.g. volta install yarn && volta pin yarn@3 for Yarn berry v3.

package.json
...
  "volta": {
    "node": "18.17.1",
    "yarn": "3.6.1"
  }
...
Enter fullscreen mode Exit fullscreen mode

It's also good to mention that Volta supports the same .nvmrc config file as nvm.

Global libraries

With Volta, the packages installed globally on your machine are associated with the correct Node version that installed them, so we are sure we use the stable packages that work on the current running Node version.

Windows support

Finally, although you might not need this, it’s nice to mention that Volta is also available on Windows, whereas nvm is only available on Mac/Linux machines.

Top comments (5)

Collapse
 
pierre profile image
Pierre-Henry Soria ✨

Any thoughts, feel free to post them below 😊

Collapse
 
sh0ckwav profile image
Stephen Stadler

In this article you claim Volta supports the same .nvmrc config file as nvm, but I don't see anything in their docs about that or an example of how-to. Please advise or update the article if it is erroneous...

Collapse
 
brianespinosa_81 profile image
Brian Espinosa • Edited

It's incorrect. Volta does not support using .nvmrc files, nor does it support using .node-version files to detect versions. This is noted in an open issue on the Volta repository.

Collapse
 
jaroslavek profile image
jaroslavek

Thanks for the nice article.
Volta is great. But I can't set up a proxy. Does anyone know how to do this?
Thank you in advance...

Collapse
 
pierre profile image
Pierre-Henry Soria ✨ • Edited

I'm super glad you enjoy the article and Volta, @jaroslavek! What kind of proxy are you trying to setup in this context?

Happy to help! 🤠