PM2 is a great tool for running Node.js applications on a web server. In my case it's an Ubuntu server with Nginx installed as a reverse proxy. I run four websites and one API endpoint from this instance, mostly without any issues.
Sometimes though the build of a Next.js application would fail, but the PM2 process would still start. This resulted in endless process restarts and led to exhausting all the server resources. All websites on this server would be unavailable due to the lack of resources.
I figured, that restarting this processes would not do anything to fix the problem, so I decided to disable this PM2 feature, by appending the option
--no-autorestart
to the PM2 start command.
In my case, the auto restart option was never used, because the processes did never crash in the first place, even after weeks of being online. Still I will have an eye on this topic, since the goal is to have the highest percentage of uptime for all websites as possible.
If you need, those are my PM2 commands:
Node.js Backend Server:
pm2 start server.js --name mywebsite.com-backend --no-autorestart
Next.js Frontend Server:
pm2 start npm --name mywebsite.com-frontend --no-autorestart -- start