DEV Community

Kahlil Lechelt
Kahlil Lechelt

Posted on • Originally published at kahlillechelt.com on

Volta

This post is about Volta and why it should be the first thing you should install on your machine as a JavaScript developer. This is how the Getting Started guide describes Volta in different places:

Volta is a hassle-free way to manage your JavaScript command-line tools.

and

Volta solves the problem of global packages

and it can

Managing your [JavaScript] toolchain

The first time I landed on the page I had problems really understanding what the Volta’s value was just by reading the descriptions. Somewhere in the docs they are talking about the “JavaScript toolchain”. I never used that term before. What does it mean?

What is the “problem of global packages”?

The definition of “JavaScript toolchain”

In order to understand which problem Volta solves, let’s define what they mean by “JavaScript toolchain”.

The JavaScript toolchain that Volta manages for you consists of all the tooling that you need in order to run and install JavaScript packages as well as globally installed command-line tools.

You can categorize these tools into three categories:

  1. The runtime, that would be Node.js
  2. JavaScript package managers, that would be npm and Yarn
  3. JavaScript CLI tools, that would be any globally installed npm package binaries

The problem of global packages

The problems of global packages are slightly different for the three categories mentioned above.

Node

The problem with a global JavaScript runtime is that you have to switch the runtime globally per project if you need different Node versions for different projects.

This can be done via a script whenever you enter the directory via command-line but the switch can be slow and any global packages you installed for one version are now not available anymore or might break because they depend on a specific version to work.

Package managers

A certain Node version comes with a certain npm version. Yarn global installs might require a certain Node version or just possibly not work with a certain version of Node.

Some projects might need different versions of package managers because they might rely on features that are differ between the version.

Global npm packages

For globally installed npm packages or JavaScript CLI tools as you might call them, the problem can be either of two things:

  1. It is installed for the currently active Node version. That means it is not available when you switch to a different version.
  2. Or it just uses whichever Node version is currently active which creates reliability issues because it might not be compatible for this version. In some cases it even needs to be recompiled.

Volta solves all of this and gets out of your way. Let me tell you how.

How Volta manages Node

Volta allows you to install Node via the Volta CLI.volta install node installs the latest LTS version of Node. You can also install a specific version with volta install node@10.15.3 for instance.

Whenever you run a Node program it will use the latest version you installed. If you need to use a specific version of Node for a project you can pin the currently active Node version to the project’s package.json with volta pin node or a different Node version with volta pin node@10 for instance.

From this point on all Node programs and locally installed npm packages that are being executed in this project are run on that pinned Node version and nothing else.

The pinning is nothing else besides an entry in the package.json. This means you can easily change the Node version by hand at any time if you want.

When you share this project via GitHub any other team member that has Volta installed on their machine will also automatically use the pinned Node version in that project. Volta will just go ahead and install it if you don’t have that specific version installed yet.

This is huge for teams. As long as Volta is installed everywhere it just takes care of using the right version per project and gets out of your way.

Many times I have experienced onboarding team members running into problems or experiencing inconsistencies because they were using a different Node version in a project.

How Volta manages package managers

Package managers can be installed and pinned per project with Volta.

On first install of a package manager Volta installs the latest stable Node version with it and binds the two so that the package manager works forever.

Via volta pin you can pin the package manager and desired version to a JavaScript project.

How Volta manages JavaScript CLI tools

Volta allows you to install any JavaScript CLI tool and will make sure it works forever once installed. If you want to install Sindre Sorhus’ tremendous Trash CLI tool you can do that by typing volta install trash-cli to use it.

Volta installs the latest LTS Node version with the tool if that version of Node was not installed yet and will always run the tool on that version of Node forever. No matter which version of Node you are using in your current project.

When you use a different Node version manager or install your Node versions globally yourself you can never be sure if all your CLI tools are working.

How it all works together

Once Node and package manager are pinned for a project and Volta is used by all devs on your team and your CI/CD automation, all weird bugs and weird behavior caused by incompatible Node and package manager versions are completely eliminated.

This tool unlocks extra stability levels for the JavaScript dev and essentially makes the toolchain much reliable.

Meaning: if your setup worked once it will definitely work again later. No matter what you globally install for other projects.

It’s one of the first things I install on a fresh system. I highly recommend you have a good look at Volta.

And on top of everything it is wicked fast because it’s written in Rust and Rust compiles down to a native binary.

Top comments (2)

Collapse
 
samarpanda profile image
Samar Panda

Do you recommend to remove nvm if we are installing volta? Wondering which one will take precedence in the case if we have both volta and nvm?

Collapse
 
kahlil profile image
Kahlil Lechelt

Definitely ditch nvm. Volta is a replacement for nvm.