If you developed with Python you know that exists the environments, a nice tool to isolate the projects to administrate versions of libraries in every project. But in frontend as node.js doesn't exists natively this function, but a third project named Volta to add this functionality in any OS.
Installation
In Windows can download the installer and follow the wizard. For Linux we can execute this command:
curl https://get.volta.sh | bash
When we install Volta we are also installing npm and node globally in the system.
Use cases
Isolate a legacy project
In this case I asume that you cloned the project from git repository so you have in basepath a file named package.json.
Your working in Angular 20 and now received the task to edit an legacy project that works in Angular 11.
In this case if you downgrade your versions of libraries sure can crash all; your main project and the legacy project. But with Volta we can solved modifying the file package.json of the legacy project to define the specific versions required (normally of node and npm).
{
"name": "app-test",
"version": "0.0.0",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build --prod"
},
"private": true,
"dependencies": {
"@angular/animations": "^11.2.14",
"@angular/cdk": "^11.2.13",
"@angular/common": "~11.2.13",
....
},
"devDependencies": {
"@angular-devkit/build-angular": "~0.1102.12",
"@angular/cli": "~11.2.12",
....
}
}
Before pin node and npm versions with Volta
First go to basepath of project and pin the version of libraries required to execute and Angular 11 project (node 14 and npm 6):
volta pin node@14
volta pin npm@6Now we can found that content of package.json has a new key named volta at the end of file:
{
"name": "app-test",
"version": "0.0.0",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build --prod"
},
"private": true,
"dependencies": {
"@angular/animations": "^11.2.14",
"@angular/cdk": "^11.2.13",
"@angular/common": "~11.2.13",
....
},
"devDependencies": {
"@angular-devkit/build-angular": "~0.1102.12",
"@angular/cli": "~11.2.12",
....
},
"volta": {
"node": "14.21.3",
"npm": "6.14.18"
}
}
After pin libraries with Volta we can see a new section named volta
After define the specific versions, now you should delete node_modules folder and package-lock.json file and reinstall all dependencies with command:
npm iCreate a new project
You need create in the basepath of project the file package.json and the content you only need to write the empty curly braces:
{}The second step is define to this project the version of the libraries with the command pin of Volta:
volta pin node@14
volta pin npm@6After the installation of specified libraries, the package.json file's content shows like as:
{
"volta": {
"node": "14.21.3",
"npm": "6.14.18"
}
}
And now with npm install your required libraries.
Member discussion: