How to run two different nodejs applications with

2020-08-04 03:58发布

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. This is the question

So we need to run the two-node js applications in the same server with node 4.8.3 and node 10.15.1

2条回答
疯言疯语
2楼-- · 2020-08-04 04:29

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

查看更多
叼着烟拽天下
3楼-- · 2020-08-04 04:45

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
查看更多
登录 后发表回答