How can you ensure everyone in your team works with the same Node engine regardless of their operating system or the package manager they use? How can you quickly develop in the same machine Javascript projects that depend on a different Node engine with varying javascript toolchains?
If you encounter those concerns, you probably know that documenting the version of the node engine and the JavaScript tools is not enough. To reproduce JavaScript environments and get the desired JavaScript environment, you must manually switch between node engines by regularly reinstalling them and their related npm package binaries. The process is error-prone and time-consuming. Furthermore, When you forget to switch between node engines, you may waste your precious time figuring out why your tool or project stopped working or does not work well anymore.
You can stop worry! Let’s see how Volta – The JavaScript Tool Manager can help you to easily reproduce JavaScript environments.
Install Volta – The JavaScript Tool Manager
The first step to reproduce JavaScript environments is to install Volta in the development machine.
To install Volta on Linux systems, invoke the following command:
Install Volta on Linux Systems
$ curl https://get.volta.sh | bash
For Windows, You can leverage the Windows Subsystem for Linux or follow the following steps:
- Allow Volta to create symlinks by enabling the Developer Mode.
- Download and install a the windows installer package of Volta.
Install Node Engines
reproduce JavaScript environments.
List All Node Engines Installed In The Machine
After installing, we can start using Volta to
First let’s see which versions of Node engines are installed with volta list all
command :
List All Node Engines Installed In The Machine
$ volta list all ⚡️ No Node runtimes installed! You can install a runtime by running `volta install node`. See `volta help install` for details and more options.
Oh, we did not install any Node engine yet. Let’s fix this issue.
Install The Latest Node Engine
Let’s install the latest Node engine:
Install The Latest Node Engine
$ volta install node success: installed and set node@14.17.5 (with npm@6.14.14) as default $ volta list all ⚡️ User toolchain: Node runtimes: v14.17.5 (default) Package managers: Packages: $ node -v v14.17.5
As we can see the Node v14.17.5 is now installed and ready to be used.
Install Specific Node Engine
Now, Suppose you need to work with a legacy project that needs Node version 12:
Install Specific Node Engine
$ volta install node@12 success: installed and set node@12.22.5 (with npm@6.14.14) as default $ volta list all ⚡️ User toolchain: Node runtimes: v12.22.5 (default) v14.17.5 Package managers: Packages: $ node -v v12.22.5
As we can see, the node version 12 is now installed and ready to use.
Switch Between Node Engines
You can easily switch between the different version of Node by invoking volta install
.
Switch Between Node Engine
$ volta install node@14 success: installed and set node@14.17.5 (with npm@6.14.14) as default $ node -v v14.17.5 $ volta install node@12 success: installed and set node@12.22.5 (with npm@6.14.14) as default $ node -v v12.22.5
To see the current node version you can also use the volta list
command:
Display The Current Tool Engine And Tools
$ volta install node@14 success: installed and set node@14.17.5 (with npm@6.14.14) as default $ volta list ⚡️ Currently active tools: Node: v14.17.5 (default) Tool binaries available: NONE $ volta install node@12 success: installed and set node@12.22.5 (with npm@6.14.14) as default $ volta list ⚡️ Currently active tools: Node: v12.22.5 (default) Tool binaries available: NONE
Now Let’s see how to reproduce JavaScript environments with Volta.
Select Your Node Engine For Your Project
The main advantage of using Volta is automatic switching to the version of Node defined in your package.json
.
Let’s see it in action.
Let’s create 2 projects, the first will use Node version 12 and the other use Node version 8.
Select Node 12 For JavaScript Project
$ cd ~projects/v12 && npm init -y npm init -y Wrote to D:\share\projects\v12\package.json: { "name": "v12", ... } $ volta pin node@12 success: pinned node@12.22.5 (with npm@6.14.14) in package.json $ cat package.json { "name": "v12", "volta": { "node": "12.22.5" } } $ node -v v12.22.5
Select Node 8 For JavaScript Project
$ cd ~projects/v8 && npm init -y Wrote to D:\share\projects\v8\package.json: { "name": "v8", ... } $ volta pin node@8 success: pinned node@8.17.0 (with npm@6.13.4) in package.json $ cat package.json { "name": "v12", "volta": { "node": "8.17.0" } } $ node -v v8.17.0
As we can see, The volta pin
command adds the volta section in package.json
with versions of the tools we choose to work with. In our case, we instruct Volta to save the version of the node engine we want to use in this project in package.json
.
Henceforward, anytime you invoke the node command inside the project directory, Volta will invoke the same version of Node you choose (That is, The version that was saved in the package.json
).
Since we commit the package.json
to our git repository, All members of our team and external collaborators who install Volta in their development machine will use the same version of our tools without any extra effort.
Reproduce JavaScript environments
With the help of Volta it is easy enforce your team to work with the same Node engine regardless and develop in the same machine Javascript projects that depend on a different Node engine. First, we see how we can use Volta to install Node engine and related tools in our development machine. Then, We see how we can select to each project the the version of the Node engine and related tools.