What the heck is PM2?

Snehil Verma
Snehil Verma
Published in
2 min readJan 3, 2020

I have been creating multiple node apps just for fun on my local machine. I know you too have created or you are creating a node application. So everything runs fine on node.js until you run your application on the terminal, but what about when you close it? Terminal can’t be running the screen every time. What about the server where you ssh things the logout from the system? Process manager comes to escape from the problem.

Process managers are the program that helps to run a process for an infinite amount of time until you forcefully kill the process. Node has multiple process manager like pm2, forever, etc. Pm2 is the npm package that is used to run your node application on the servers so that even if you logout from the server the process will not stop. Pm2 also restart the process if the application crashes at any point.

To install pm2 we have to use the pet npm command:

npm install pm2

Pm2 provides you monitoring by the command

pm2 monit 

It helps you to monitor the real-time application like the percentage of memory used, real-time logs, CPU utilisation, etc.

Pm2 allows setting multiple environments in the ecosystem file. The command to generate the default ecosystem file is:

pm2 ecosystem

To start the application with a particular ecosystem the command is as follows:

pm2 start ecosystem.config.js --env [environment_name]

To learn more about pm2 follow the documentation which I find the best place to learn pm2. Here is the link to the documentation.

https://pm2.keymetrics.io/docs/usage/pm2-doc-single-page/.

--

--