Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PM2 not taking the latest version of nodejs installed

Previously, I had node version v0.10.46 installed on my ec2 server. For a recent project, I decided to give pm2 a try and installed pm2 using npm install pm2 -g.

But, pm2 start index.js errored out since the project was using some ES6 syntax with arrow functions and let keyword.

enter image description here

Therefore, I updated the node version using nvm to latest v6.9.1, which is also the same version which we used for developing on local (windows).

However, pm2 start index.js again errored out with the same error:enter image description here

pm2 show index hinted that the nodejs version was still not updated. I removed the old nodejs version, installed pm2 again, still of no avail.

I tried with other methods as well, by using:

pm2 start index.js --interpreter=~/.nvm/versions/node/v6.9.1/bin/node

to force pm2 to use the latest installed version of node. Every single try gave me the same errors with the same version of nodejs. Why is Pm2 not taking the latest version of node and sticking with 0.10.46?

If it helps:

which node
~/.nvm/versions/node/v6.9.1/bin/node
which pm2
~/.nvm/versions/node/v6.9.1/bin/pm2

Also, v0.10.46 was NOT installed using nvm.

Edit: Here are the running pm2 daemons, using ps -ef | grep pm2:

pm2 daemons

Note that ec2-user is the logged in user and I also tried the same with root user. I installed nvm running node v6.9.1 and pm2 as root user as well with no success. I get the same error.

like image 797
A.I Avatar asked Jan 17 '17 18:01

A.I


People also ask

How do I update pm2 NPM?

In console : pm2 save --First make sure that you saved correctly all your processes. npm install pm2 -g --Then install the latest PM2 version from NPM. pm2 update --And finally update the in-memory PM2 process.


1 Answers

NVM allows you to run multiple version of node at a single time (between multiple shells). This means that when you run nvm use you are using that version of node within the context of that running shell.

Given PM2 runs as a daemon, I believe it kicks off its own process which is why it is not using the current nvm selected version.

This GitHub issue shows the usage of the interpreter flag which might be helpful for your specific issue https://github.com/Unitech/pm2/issues/1034


If the actual issue here is with the PM2 process needing to be running a specific NodeJS version, instead of an application PM2 is spawning, restarting the PM2 dameon itself after running the nvm use would have it startup with the current version of Node selected by nvm.

like image 158
Kody Avatar answered Sep 22 '22 16:09

Kody