While NVM has its uses, I encourage you to consider an alternate option.
You can pin you project to a particular version of Node.js using the node
package on Npm!
cd oldProject
npm i node@6.11.5
cd ../newProject
npm i node@9.0.0
Next time Npm runs node
, it will use that version!
The node
package accomplishes this by downloading the specified version of Node.js to node_modules/.bin/node
. You you can run it directly, but it is easier to let Npm run it.
Any package.json#scripts
will automatically use the specified version of node
since node_modules/.bin
is added to the path by Npm.
No more remembering which version of Node this package uses.
No need to run anything new - just make sure npm i
has been run.
{
"scripts": {
"node-version": "node --version"
},
"dependencies": {
"node": "9.0.0"
}
}
Note, you will need to npm install
once before the correct node
is used:
node --version
# v18.12.0
npm run node-version
# v18.12.0
npm install
npm run node-version
# v9.0.0
node --version
# v18.12.0
node_modules/.bin/node --version
# v9.0.0