Managing Node.js with Volta

Managing Node.js with Volta

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 ran 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.


The installation is simple.

# install Volta
curl | 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.