How to use different versions of Node simultaneously using NVM - node.js

Steps we have tried :-
1) We installed nvm and its node version in our CI server.
2) There are two projects. Both use different versions of node.
3) When we run 'nvm use version' . Same node version is set for both the projects. Due to this simultaneous build is not working.
Is it possible to use different versions of node simultaneously.

Works for Linux. You can see I have two versions of node is installed in my machine
-> v10.15.3
v12.10.0
Then I ran
`nvm alias default node`.
In the current cli my node version is 10.15.3.
Now open another cli window and check that. For me that is is 12.10.0.
So set a default version then change around it using
nvm use your_desired_version
. See below image.

Related

What is a sustainable method to upgrading node from old versions to latest?

I would like to upgrade a few projects from Node 8 to the latest Node version.
Amazon mentioned that Node 12 is now deprecated.
I assume there is much more to consider than simply upgrading the package version, considering these projects would have many packages installed and there could be breaking changes.
What is the approach I should take in upgrading them to the latest Node version without breaking existing functionality?
Updating
It depends on how are you running Node. If it is inside a docker container, you may update the image definition in your docker.compose file:
(note: I am using 16 as demo here)
# specify the node base image with your desired version node:<version>
FROM node:16
If you have it deployed as a Node project, you can set the engines field in your package.json:
"engines" : {
"node" : ">=16.0.0"
}
Lastly, if we are speaking about your local computer, you can uninstall Node and re-install the wanted version or use a version manager, like nvm.
Updating locally with nvm:
nvm install 16.0.0
nvm use 16.0.0
Considerations
Make sure everything works and that your dependencies can run in the new environment. A robust test suite and a proper CD/CI pipeline are essential to guarantee appropriate functioning.
$ yarn global add n
$ n latest
or
$ npm install -g add n
$ n 18
n allows you to manage several node versions with ease, i've been using it for years

How can I choose node version for ng build command?

I have two different version of node version installed - 11.6 and 13.6. 13.6v is set in path variable so that is default node. I have a project which needs to be built only using 11.6v. But my ng command is using node 13.6 by default (I checked this using ng --version). Is there anyway I can ask ng to use node from a specific folder where I have 11.6 installed instead of the default one.
Edit: This is on Jenkins VM, so I don't have much access to change things.
I think the easiest way to work with different versions is using nvm tool.
See:
https://github.com/nvm-sh/nvm

How to run two node versions on linux system?

How to run two different node versions parallel on same system? I've tried looking for solution on web, but all solutions are about switching node versions.
nvm run {version} {command}
e.g.
nvm run 9 abc.js
This will run with Node.js v9
More info on: https://medium.com/#luongnhutoan/how-to-run-multiple-versions-of-nodejs-with-nvm-3c40aa25c359

Set node version differently for specific project(folder) via NVM

I know I can change the node version by nvm use CLI command. However, I want to set specific node version differently for a certain project(folder). It's changed via nvm use command but it's reverted to default version whenever I restart the terminal or webstorm IDE.
How can I set nvm remember this different version for a certain project(folder)?
You can use an .nvmrc file in the root of the project with the version you want to use. For example v12.4.0 or v10.16.0.
You have to make sure that this version is installed or it will use the default node version in your machine.
For example, you want your default node version for this project to be v12.
Open your command line in the project root folder, then run nvm use 12, then run node -v > .nvmrc.
It won't solve your issue completely because you'll anyway have to run nvm use just without the version.

Using nvm for running a single command with different node version

I have node 8 required for my project, but I need to use node 10 for running one of my build command. Is it good to use nvm for running single command with different node version or shall I upgrade my project with higher node version?

Resources