admin管理员组文章数量:1287809
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.
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:
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
:
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.
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.
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:
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
:
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.
Share Improve this question edited Jan 17, 2017 at 19:53 A.I asked Jan 17, 2017 at 18:23 A.IA.I 1,4482 gold badges16 silver badges18 bronze badges 2- is the pm2 daemon running as the same user as you are logged in as, or is it a different user? – Paul Commented Jan 17, 2017 at 18:31
- @Paul updated the question, hope that helps. It is the same user. – A.I Commented Jan 17, 2017 at 19:03
2 Answers
Reset to default 7NVM 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./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
.
If you want pm2 to use a specific version of node, use the following two directives in your ecosystem.config.js
file:
{
...
exec_mode: "fork",
interpreter: "[email protected]", // or any installed version
...
}
It is mandatory to use exec_mode: "fork"
, otherwise your node application will be create as a child process of your main pm2 process, which uses the node version the system is currently using.
本文标签: javascriptPM2 not taking the latest version of nodejs installedStack Overflow
版权声明:本文标题:javascript - PM2 not taking the latest version of nodejs installed - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741319324a2372113.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论