问题
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
回答1:
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
回答2:
Use NVM to install two different versions of nodejs. Then switch to respective node versions when you run.
来源:https://stackoverflow.com/questions/57669518/how-to-run-two-different-nodejs-applications-with-two-different-node-version