How can I run pm2 on a certain node version?

耗尽温柔 提交于 2019-12-23 07:38:27

问题


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


回答1:


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'



回答2:


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.




回答3:


Please read the following thread: Using different versions of node via nvm for each app

I believe you wanted to hack around the nvm, but believe me it can save much of your time.

You can find a comment in the thread from the pm2 owner itself, which states you can run multiple apps on different node versions, here is a JSON conf content:

{ 
  apps : [{
    name : 'API',
    script : 'api.js',
    interpreter : 'node@6.9.1'
 }]
}

If you are interested in the solution above, please read through the documentation here: PM2 - process file

PM2 empowers your process management workflow. It allows you to fine-tune the behavior, options, environment variables, logs files of each application via a process file. It’s particularly useful for micro-service based applications.

Configuration format supported are Javascript, JSON and YAML.




回答4:


install https://github.com/creationix/nvm

then install specific node version:

nvm install 0.11.14

than in a shell use the specific version:

nvm use 0.11.14

node -v // v0.11.14


来源:https://stackoverflow.com/questions/29739715/how-can-i-run-pm2-on-a-certain-node-version

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!