Pm2 Cheat Sheet

Pm2 Cheat Sheet

Here is a quick cheat sheet of pm2 commands:-

Installing pm2

npm install pm2 -g

Start and name a process

pm2 start app.js --name myApp

Start and auto-restart on file change

pm2 start app.js --watch

List apps

pm2 list /*Shows all the processes*/
pm2 prettylist /*Prints process list in beautified JSON*/
pm2 describe 0 /*Display all information about a specific process*/
pm2 monit /*Monitor all processes*/

Logs

pm2 logs  /*Display all processes logs*/
pm2 flush  /*Empty all log files*/
pm2 reloadLogs /*Reload all logs*/

Misc

pm2 status /*Shows process status(online, stopped, errored), restart count, uptime, cpu and memory usage*/
pm2 stop id|name /*Stop a process*/
pm2 restart id|name /*Restart a process*/
pm2 delete id|name /*Delete a process*/
pm2 stop all /*Stop all processes*/
pm2 restart all /*Restarts all processes*/
pm2 delete all /*Removes all processes from pm2 list*/

Some extras

ENV_VARIABLE_NAME="VALUE" pm2 restart <pid> --update-env /*This will add an environment variable to your process*/
pm2 env <pid> /*This will print all the process.env variables*/