PM2 is designed to be an enterprise-level process manager. As discussed elsewhere, Node runs within a Unix process, and its child process and cluster modules are used to spawn further processes, typically when scaling an application across multiple cores. PM2 can be used to instrument deployment and monitoring of your Node processes, both via the command line and programmatically. PM2 spares the developer the complexity of configuring clustering boilerplate, handles restarts automatically, and provides advanced logging and monitoring tools out of the box.
Install PM2 globally: npm install pm2 -g
The most straightforward way to use PM2 is as a simple process runner. The following program will increment and log a value every second:
// script.js
let count = 1;
function loop() {
console.log(count++);
setTimeout(loop, 1000);
}
loop();
Here, we...