Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I run pm2 on a certain node version?

Tags:

node.js

pm2

There are several different versions of node running on our linux server, And my service is based on node v0.11.14. However, other people's code have to run on lower version of node(lower than v0.11) otherwise their services will be out of service. So I can't define the global node version as v0.11. I just want to run pm2 to monitor my service based on node v0.11.

Is there anyway to run my pm2 on node v0.11 without changing the global node version? Thanks

like image 639
hwoarangzk Avatar asked Apr 20 '15 05:04

hwoarangzk


People also ask

Does pm2 need to be installed globally?

yes, you need to install it globally.


2 Answers

Use pm2 and specify node version using --interpreter flag with node version absolute path:

sudo pm2 start app.js --interpreter=/home/ken/.nvm/v4.4.2/bin/node

or

sudo pm2 start app.js --interpreter=/home/ken/.nvm/v7.4.0/bin/node

etc..

If you change the node version wherever I mentioned --interpreter="***.." the app will run in exact node version.

Once you completed the above approach to verify use following command

sudo pm2 show 'app name'
like image 129
KEN Avatar answered Oct 20 '22 08:10

KEN


To run several version at the same time. In pm2, you can use the --interpreter options and specify the path to the node version you want.

If you use n for version run n bin v4.2.0 to get the path to this node version.

like image 30
Sylvain Avatar answered Oct 20 '22 08:10

Sylvain