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?
To install volta on UNIX-based systems(macOS & Linux).
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 and follow the instructions.
To install Node.js & NPM
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.
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.
$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.
$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 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.