How can I run pm2 on a certain node version?

hwoarangzk picture hwoarangzk · Apr 20, 2015 · Viewed 24.9k times · Source

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

Answer

KEN picture KEN · Jan 22, 2019

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'