DEV Community

loading...
Cover image for Easy JavaScript Toolchain Management with Volta

Easy JavaScript Toolchain Management with Volta

Paul Arah
・2 min read

Summary: Use Volta for managing everything JavaScript. It's easy, flexible and convenient.

A common problem JavaScript developers face is managing multiple versions of the toolchain we use. Toolchain here refers to Node.js, NPM, TypeScript and everything in between you'd use for working with JavaScript.

I personally have had scenarios where I'd install the needed dependencies for a project and then discover the project isn't compatible with the version of my global installation of Node.js. I'd then have to delete the dependencies, flush my cache, install the right version of Node.js, then install the dependencies for the project all over again.

This begs the question, how do we seamlessly manage different versions of your toolchain across different projects?

Volta to the rescue! Volta is a hassle-Free JavaScript tool manager. Volta allows you easily switch between multiple versions of your toolchain depending on the project requirement. Your team can define a specific version of the toolchain for a project and this stays consistent for everyone making your environment easily reproducible.

To install volta on UNIX-based systems(macOS & Linux).

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

Close your current shell session and open a new one for the changes Volta made to fully take place.

For Windows, download and run the Windows installer and follow the instructions.

To install Node.js & NPM

volta install node
Enter fullscreen mode Exit fullscreen mode

Now we have Node.js globally available. You can specify the version of Node else it automatically defaults to the LTS version.

Managing your Toolchain Across Projects

To pin a specific version of Node.js to a project, run the command below in the root directory of the project.

volta pin node@12
Enter fullscreen mode Exit fullscreen mode

Checking for the node version outside the project directory would give you the version of your global installation when you originally installed node with volta. Navigating into the project directory and checking the node version would give the node version specific for this project.

$cd home/some-js-project 
$volta pin node@12
$node -v #gives you node version 12 
$cd ../
node -v #gives you node version 14
Enter fullscreen mode Exit fullscreen mode

Assuming your global installation of the typescript compiler is version 4.2 and your project uses version 3.2. Volta automatically detects manages this for you.

$npm i typescript -g
tsc --version #4.2
$cd some-js-project
$tsc --version #3.4
Enter fullscreen mode Exit fullscreen mode

Under the hood, volta works by replacing your global node command with a shim that downloads the right version of your tools for you. Volta is written in rust and shipped as a single binary, thus it's very lightweight with a small overhead. There are also Github actions for it, making it easy to use in your CI. If you need to extend the functionality of Volta, volta has some advanced features like hooks that allow you do this.

Volta works out of the box with no stress. Now we can go back to doing more important things like frying eggs and cooking Jollof Rice.

Discussion (0)