Easy JavaScript Toolchain Management with Volta
Tags: javascript, node, typescript, webdev
Published: 2021-04-20 04:20:58

**Summary:** Use [Volta](https://volta.sh) 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). 

```bash
curl https://get.volta.sh | bash
```
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](https://github.com/volta-cli/volta/releases/download/v1.0.3/volta-1.0.3-windows-x86_64.msi) and follow the instructions.
 
To install Node.js & NPM 
```shell
volta install node
```
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
``` 
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. 
```bash
$cd home/some-js-project 
$volta pin node@12
$node -v #gives you node version 12 
$cd ../
node -v #gives you node version 14
``` 
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.

```bash
$npm i typescript -g
tsc --version #4.2
$cd some-js-project
$tsc --version #3.4
``` 

Under the hood, volta works by replacing your global node command with a [shim](https://en.wikipedia.org/wiki/Shim_(computing)) 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.