Managing Node.js with Volta

Subscribe to my newsletter and never miss my upcoming articles

I recently wrote a blog post about how I use NVM to manage my node version. Someone commented on the post saying I should look into Volta

What is Volta

Volta is a command line tool used to manage your Node.js. It is built using Rust and is shipped as a static binary that can be run on Windows and all *nix shells. The goal is to make sure every developer working on the project seamlessly has the same tools and versions installed.

Installation

The installation is simple.

# install Volta
curl https://get.volta.sh | bash

The script installs the binary in ~/.volta and adds ~/.volta/bin to your systems path inside of your ~/.bash_profile, ~/.profile, and ~/.bashrc.

export VOLTA_HOME="$HOME/.volta"
export PATH="$VOLTA_HOME/bin:$PATH"

Now you can start using Volta to manage Node.js.

Using Volta

You can easily install node using

# Install node
volta install node
# or you can install a specific version
volta install node@12

Now node should be available to use whenever you open your terminal.

If you want to set Volta to always load a specific version of node for your active package you can use pin.

volta pin node@12.18.3

This command will store your pinned version in your package.json.

"volta": {
  "node": "12.18.3"
}

Every time you navigate to your project, Volta will automatically set your active node version to whatever is pinned.

You can even install and pin global packages like yarn using Volta to make sure everyone on your team is using the same version for their global packages.

volta install yarn
volta pin yarn

How does Volta compare to NVM?

NVM is just a node version manager. It only handles installing different versions of node. You can also set a default version of node to load whenever you open your terminal. Volta handles node versions and can set a default version to load also.

When opening a terminal, NVM usually takes about 0.5 to 2 seconds to source in bash if you have a default node version set. Volta does not seem to add any load time.

You can pin node version for your projects using both tools. NVM uses a .nvmrc file and Volta adds a key to your package.json. Volta can also pin versions for global NPM packages used for the project.

NVM does not automatically switch your active node version to your pinned version. You have to run nvm use or install another package call AVN. AVN usually takes 2 to 5 seconds to switch node versions. Volta does it automatically and usually takes less than a second.

What tool will I be using?

Even though I have been using NVM for almost 4 years, I think Volta takes the crown. I plan to use Volta for managing all my Node.js needs from now on. The speed and simplicity of the tool just makes it the better choice. NVM, I am thankful you for all the headaches you have saved me in the past but I think it is time to move on.


Comments (3)

Max Programming's photo

I haven't used nvm yet because I want to work with the latest version of node. But sure I wanna try out this new thing: Volta.

Does this mean that we can install a specific version of node for a specific project we wanna build? 🤔

Thanks for bringing this to us Corey!

Corey O'Donnell's photo

Hey max,

I work on multiple projects that all require a different version of node. Both NVM and Volta allow me to easily install and switch between the different versions.

I do recommend trying each one out yourself.

Max Programming's photo

Corey O'Donnell Yes but, I personally haven't encountered any issue with any version of node.

If possible, can you please write a blog-post on what is the need for using different versions of node