PM2 commands cheat sheet list.


PM2 commands cheat sheet list.

In this article, I will be discussing on “PM2 commands cheat sheet list”. How to manage the NodeJS process by PM2.

PM2 is a Process Manager that monitors the node process and keeps the server up and running all the time.

With the help of PM2, we can set up clustering for the NodeJS process. To install the PM2 is very simple task.

It also provides log management via PM2-logrotate, where it takes care of the logs. Like retain, compress, rotate, and delete the logs.

So I have divided PM2 Commands Cheat Sheet into 5 different categories,

  1. PM2 Commands to list the process.
  2. How to Manage logs with PM2.
  3. Action Commands for PM2.
  4. How to Delete the Process via PM2.
  5. How to use Cluster mode with PM2 commands.

1. PM2 Commands Cheat Sheet to list the process.

So listing is very easy when you are using PM2. It will list the process that is running or stopped.

$ pm2 list

Now let’s assume there are 2 processes running on your system. And you want a detailed description of the 1st process.

$ pm2 describe 1

#1 is the PID of the Process

2. How to Manage logs with PM2.

To check the current logs for the running process.

$ pm2 logs

How to check the current logs for a Particular ID in PM2?

$ pm2 logs 1 

3. How to Manage Process via Action Commands.

How to start the NodeJS Process in PM2.

$ pm2 start tla.js

To start the NodeJS process with the Name.

$ pm2 start tla.js --name Tastethelinux-App

Start the Process by ID in PM2

$ pm2 start 1

To Start all the processes in PM2

$ pm2 start all

How to Stop all the running process in PM2

$ pm2 stop all

Stop the Process by ID in PM2

$ pm2 stop 1

To Stop the Process by name in PM2

$ pm2 stop Tastethelinux-App

Restart all the Process in PM2

$ pm2 restart all

To restart the process by ID in PM2

$ pm2 restart 1

Restart the Process by Name in PM2

$ pm2 restart Tastethelinux-App

4. PM2 Commands Cheat Sheet to delete the Process.

Delete the Process by Name.

$ pm2 delete Tastethelinux-App

To delete the process by ID.

$ pm2 delete 1

Delete all the processes in PM2.

$ pm2 delete all

5. Use PM2 Commands as a Cluster-Mode.

How to run the application in Cluster mode.

$ pm2 start tla.js -i 0

How to run the max pm2 cluster for NodeJS

$ pm2 start tla.js -i max

Run the PM2 cluster with 4 process

$ pm2 start tla.js -i 4

Scale up the PM2 cluster with 2 more processes.

$ pm2 scale tla.js -i +2

Scale down the PM2 cluster.

$ pm2 scale tla.js -i 3

Now this will run only 3 instances in the system.

If you want a detailed explanation of PM2 commands you can refer to the link. The link to the NPM package of PM2.

Give your valuable time