I had node version v6.11.1 installed but it was giving error in some package, so i installed v10.15.3 with nvm and set it as default.
#If I run my app directly using node, it uses correct node version v10.15.3 and works
node server.js
#If I run using pm2 it uses old node version v6.11.1 and causes error.
pm2 start server.js
I tried passing --interpreter like
pm2 start server.js --interpreter=~/.nvm/versions/node/v10.15.3/bin/node
#but even this uses v6.11.1
I verify the node version by printing process.version inside my app.
Switching among Node. 7; we can simply run either nvm use 12.22. 7 or nvm use 16.13. 0 to easily switch into either version we need. Note that since we only have one version that begins with 12, 14, or 16, we can switch versions with a simple nvm use 16 , nvm use 14 , or nvm use 12 command.
As on the same machine, we can only install one version of the nodejs, so it's very painful to uninstall and install the new node version as per your project requirements. To overcome this problem, we can use the Node Version Manager (NVM).
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. Show activity on this post.
Nodejs can be upgraded or downgraded using different methods some of them are by manually downloading the latest version of node from their official nodejs.org website and the second method is by using nvm which is really helpful in controlling the node version.
For later fellow googlers:
pm2 update
did help me in a similar case.
Found here: https://github.com/keymetrics/pm2-plus-tech-questions/issues/88
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With