Node.js pm2 keeps restarting almost every second
Check if your app modifies a file in the project folder (such as a log file). A change to any of the files triggers restart if watch
flag is enabled.
To prevent this, use a process
file and add watch_ignore
flag in it.
Here's a documentation on how to use the process file:PM2 - Process File
pm2 writes application logs to ~/.pm2/logs
and pm2 specific logs to pm2.log
by default. We need to check both the locations to debug the issue.
One other way to debug application is by starting the application manually, ie., something like npm run start
or node path/yo/your/bin.js
It should give you the missing piece of information to fix the problem and move on.
We also faced a similar problem where pm2 was restarting a process to start a node.js web application almost every second.
We found that MongoDB was not running, and then the web application would try to connect to the database on start up but would fail. This would prompt pm2 to restart the process over and over, causing a restart every second.
If this is your issue, try to start MongoDB with mongod
or mongod --dbpath [your db path]
?