DEV Community

loading...
Cover image for Have you heard of Volta?

Have you heard of Volta?

jamiedavenport profile image Jamie Davenport Originally published at jamiedavenport.dev ・3 min read

Welcome to the first post in my Have you heard of series where I find new and niche technologies then try to explain them as simply as possible. I'll try to explain the problems that they solve, compare them to competitors and figure out who, if anyone, should use these tools.

This post is all about Volta, enjoy!

GitHub logo volta-cli / volta

Volta: JS Toolchains as Code. ⚡

Volta is a "the hassle-free JavaScript tool manager". What does that mean? Well, it helps you to manage multiple versions of node, npm and yarn for your projects and conveniently switch between them (hence "hassle-free").

It can be installed with a single line and comes with automatic setup and completions for popular shells. Go ahead, try it now:

curl https://get.volta.sh | bash
Enter fullscreen mode Exit fullscreen mode

What's the problem

It's the age-old problem of "it works on my machine". This occurs frequently when multiple people are working on a single project such as in a large enterprise or open-source.

As a developer, you probably have multiple projects that you work on. Each might depend on a different toolchain to the other. How do you manage all these different toolchain versions? It would be funny if the answer wasn't Volta.

The solution

Volta provides two important commands that solve this problem: volta install and volta pin.

First, volta install, it does what it says on the tin. It installs a specific version of a tool globally e.g. volta install node@12. This becomes the default on your machine which is used as a fallback for any projects that don't specify a version.

Secondly, volta pin allows you to set a version of a tool for the current project e.g. volta pin node@14. This gets stored in the package.json and is shared between all developers.

// package.json
"volta": {
  "node": "14.15.4",
  "yarn": "1.22.5"
}
Enter fullscreen mode Exit fullscreen mode

Here's the cool part, Volta automatically switches your toolchain whenever you change directory 🤯

Automatic toolchain switching example

If you don't have the required version installed, then Volta installs it for you. This happens whenever you try to use the tool for the first time.

Automatic installation example

Example

Here's a couple of projects that I've used Volta with:

I've also found that Volta works well in CI (example), there's even a Github Action for it 🥳

Meet the competition

NVM

NVM is a popular tool for managing multiple Node versions on a single machine. I've used NVM for a long time before now, and it's served me well.

NVM can detect the node version for a project using a .nvmrc file, but you have to manually call nvm use to switch versions or manually configure your shell to do so.

Volta also feels a lot more responsive, this is my opinion, and I'd suggest trying out both.

Docker

When you think about solving the "it works on my machine" problem, you probably think of Docker. And you should, Docker is awesome. It solves the problem, works great with CI and containers are a popular deployment target (ECS & Kubernetes).

However, it does have a much greater learning curve than Volta, and the development workflow is a lot slower, with time spent waiting for Dockerfiles to build. If you're not already using containers in your workflow, I'd suggest using Volta!

For the enterprise

Volta makes a great tool for any solo developer but it also fits in with large organisations. In addition to the problems we've already discussed, Volta also makes onboarding a breeze:

  1. Install Volta
  2. Clone projects
  3. Profit 🤩

Volta can be configured to fetch binaries from other places such as your company's private registry. It even includes support for monorepos! That thing that all the cool companies are using.

Community

We're all in this together 🎶 and Volta is no exception.

We've reached the end

I've tried to describe Volta very briefly, and from a high level, so much of the specifics have (deliberately) been glossed over. If you want to learn more about Volta, see their top-quality documentation.

If you've enjoyed this post then please let me know on Twitter. Feedback is always appreciated.

Have a great day ❤️

Discussion (0)

pic
Editor guide