Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to automatically reload Node.js project when using pm2

Tags:

People also ask

Does pm2 auto restart?

PM2 will keep your application forever alive, auto-restarting across crashes and machine restarts.

Does pm2 auto restart after reboot?

The start script sets up PM2 as a service under the init system. When the server restarts, it will automatically restart PM2, which will then restart all the Node. js applications/processes it is managing. In this article, we will show you how to deploy PM2 as a service to reliably manage your Node.

What does pm2 reload do?

With reload, pm2 restarts all processes one by one, always keeping at least one process running. It also states that: If the reload system hasn't managed to reload your application, a timeout will fallback to a classic restart.


I am currently programming Node.js with Express.js, and every time I change a line of code in the file router or app, I need to type the command:

pm2 reload id_project. 

How do I make pm2 auto-reload the project when a file is changed?