preface

When I read webstorm’s update log yesterday, I found that it has added Volta integration. When I first saw it, I was curious about what it was, so I tried it for the first time.

After some exploration, we know what it does and what development pain points it solves. This article will share with you the installation and use of Volta, a powerful JavaScript tool manager. Welcome interested developers to read this article.

Environment set up

Developed using RUST, Volta has no external dependencies and is particularly easy to install.

Install on MacOS and Linux

Open the terminal and execute the following command:

curl https://get.volta.sh | bash
Copy the code

The following interface is displayed after the installation is successful:

Careful developers may have noticed that the volta command is not available after installation because it has not yet taken effect after being added to the environment variable. We need to execute the following command for it to take effect:

source ~/.bash_profile
Copy the code

Finally, we execute volta again and it works.

Install it on Windows

To install on Windows, you need to download the volta installation package as prompted.

Click next to complete the installation. Open CMD or Powershell and execute volta command to verify whether it takes effect, as shown below:

Usage scenarios

With the environment set up, let’s take a look at its usage scenarios.

Manage the global JS package version in your project

For front-end developers, most of the work involves Node and various package management tools (YARN, PNPM, etc.). If you, as the technical leader of a team, want to unify the version of the package installed on the computers of your team members, you usually write the version number required to run the project into the readme.md file. Team members install their own versions of the software.

This method is obviously uncomfortable, when there are multiple projects, each project depends on a different version of Node, you need to open the project every time to check the version number of the project, manually switch the node version, reducing the development efficiency.

Volta solves this pain point by simply adding the volta field to your project’s package.json and writing the version number as follows:

"volta": {
  "node": "14.16.0"."yarn": "1.22.17"
}
Copy the code

The team members only need to set up the environment of Volta on their computers and start the project to successfully complete the version switch 🤓. As shown in the following figure, we respectively executed Node –version in the root directory and global location of the terminal, and got different results, which proves that the version switch has been successful.

More usage

In its official documentation, it also provides more ways to use it as a JS package versioning platform for your system, managing Node, typescript, Nest, and a host of other JS packages.

The three most commonly used commands are:

  • Install Installs a package as follows:
# @ Specifies the version number, which can be ignored. If omitted, the latest version will be installed by defaultVolta install [email protected]Copy the code
  • List displays the global JS package version number used by the current project as follows:
volta list
Copy the code

  • Pin Switch the package version number written in package.json as follows:
Volta pin [email protected]Copy the code

For more instructions, please refer to volta-Reference

Write in the last

At this point, the article is shared.

I’m an amazing programmer, a front-end developer.

If you are interested in me, please visit my personal website for further information.

  • If there are any errors in this article, please correct them in the comments section. If this article helped you, please like it and follow 😊
  • This article was first published in the magic programmer public number, without permission to prohibit reprinting 💌