How can I run pm2 on a specific version of node?

There are several versions of node on our Linux server, and my service is based on node v0.11.14. However, the code of other people should work in the lower version of node (lower than v0.11), otherwise their services will be inoperative. Therefore, I cannot define the global version of node as v0.11. I just want to run pm2 to monitor my service based on node v0.11.

Is it possible to run my pm2 on node v0.11 without changing the global version of node? Thanks

+6
source share
4 answers

In run several versions at once. In pm2 you can use the --interpreter options and specify the path to the version of node you need.

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

+5
source

Read the following topic: Using different versions of node via nvm for each application

I believe you wanted to hack nvm, but trust me that this can save most of your time.

You can find a comment in the stream from the owner of pm2 itself, which says that you can run several applications in different versions of node, here is the contents of conf JSON:

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

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

PM2 allows you to control the workflow of a process. It allows you to configure the behavior, parameters, environment variables, log files of each application through the process file. This is especially useful for microservice applications.

Supported configuration format: Javascript, JSON and YAML.

+2
source

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

then install the specific version of node:

 nvm install 0.11.14 

than in the shell, use a specific version:

 nvm use 0.11.14 node -v // v0.11.14 
+1
source

Use pm2 and specify the node version using the --interpreter flag with an absolute node version 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 version of the node wherever I mentioned --interpreter="***.." application will work with the exact version of the node.

After you have completed the above approach, to check, use the following command

 sudo pm2 show 'app name' 
0
source

Source: https://habr.com/ru/post/985483/


All Articles