Upgrading Node.js and PM2 apps - lessons learned
This post is for people running Node.JS Apps using the PM2 Process Manager. I recently updated my applications from Node V12.x LTS to V14.x LTS due to an update of the AppDevPack to release 1.0.9.
So what happended ? The update is straight forward:
- Stop your running apps in PM2
- Update Node.js in NVM by installing the latest LTS Build in V14.x
- Update PM2 to the latest version by npm i pm2@latest -g
- Update the projects to the new domino-db version and npm install
- Restart the apps in PM2
Errors ! WTF ?! Each app produced the following error in the domino-db Module:
this.#secure = Boolean(connection?.secure);
SyntaxError: Unexpected token '.'
at wrapSafe (internal/modules/cjs/loader.js:915:16)
at Module._compile (internal/modules/cjs/loader.js:963:27)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
at Module.load (internal/modules/cjs/loader.js:863:32)
at Function.Module._load (internal/modules/cjs/loader.js:708:14)
at Module.require (internal/modules/cjs/loader.js:887:19)
at Module.Hook._require.Module.require (/home/notes/.nvm/versions/node/v14.16.0/lib/node_modules/pm2/node_modules/require-in-the-middle/index.js:80:39)
at require (internal/modules/cjs/helpers.js:74:18)
at Module._compile (internal/modules/cjs/loader.js:999:30)
After poking around, I found using
pm2 describe <app>
that PM2 stores the Node Version that the app ran with previously in an environment variable. Me using NVM, the old version was still there so the APP startet still with Node.js V12.x !
I had to delete my apps from PM2 by doing
pm2 delete <app>
and re-integrate it again using
pm2 start <app>
to pick up the changes in Node.js.
After that, all apps are running fine again. Maybe there's a better way to do this, but heck, this worked for me.
Hope this helps if needed.