5

We have two node js applications. This two applications won't work in the same node version, one application only works in node4.8.3 another one application only works in node10.15.1.

How do we run different Node.js versions on the same server simultaneously?

jens.klose
  • 351
  • 2
  • 8
Bala
  • 117
  • 4
  • 13
  • Possible duplicate of [How can I change the version of npm using nvm?](https://stackoverflow.com/questions/9755841/how-can-i-change-the-version-of-npm-using-nvm) – AZ_ Aug 27 '19 at 07:28
  • one option is to use docker. – nirazlatu Aug 27 '19 at 11:49

2 Answers2

5

You can use docker to run multiple Nodejs version simultaneously. this might be useful for you: https://nodesource.com/blog/containerizing-node-js-applications-with-docker

https://blog.hasura.io/an-exhaustive-guide-to-writing-dockerfiles-for-node-js-web-apps-bbee6bd2f3c4/

There are other useful resources available on the internet on containerizing Node app on docker.

Docker could be a better choice here but if you don't want to use docker, you can use the nvm run command to target specific versions without switching the node variable:

nvm run 4.8.3 nodeapp1.js

For the other node version :

nvm run 10.15.1 nodeapp2.js

Using forever :

forever start -c /home/ubuntu/.nvm/v10.15.3/bin/node nodeapp1.js

forever start -c /home/ubuntu/.nvm/v4.8.3/bin/node nodeapp2.js
Bala
  • 117
  • 4
  • 13
Sandeep Patel
  • 4,815
  • 3
  • 21
  • 37
  • Thanks for your answer, Is there any other way without docker? Please share your options – Bala Aug 27 '19 at 11:38
  • Thank your response, it's working with two different versions and I have used forever with the node using below commands. Thank you. `forever start -c /home/ubuntu/.nvm/v10.15.3/bin/node nodeapp1.js` `forever start -c /home/ubuntu/.nvm/v4.8.3/bin/node nodeapp2.js` – Bala Aug 28 '19 at 14:32
0

Use NVM to install two different versions of nodejs. Then switch to respective node versions when you run.

prisar
  • 3,041
  • 2
  • 26
  • 27
  • 3
    Yes that's great, Using NVM we can switch the node js version but we cannot run the two-node version at the same time. – Bala Aug 27 '19 at 07:30
  • then you have to use put your application in some container like docker container then it wouldn't be a problem – prisar Aug 27 '19 at 08:38