DEV Community

Cover image for PM2 Cheat Sheet & Process Management Guide
Hamid Shoja
Hamid Shoja

Posted on • Edited on

PM2 Cheat Sheet & Process Management Guide

Hello friends,
I've created another cheatsheet, it's for pm2, which is actually my personal notes like the other articles. It could be helpful for you too.

PM2 (Process Manager 2). PM2 is a production process manager for Node.js applications that helps keep your apps alive, simplifies logging, and enables zero-downtime deployments.

🚀 Key Features

  • Process Management: Easily start, stop, and restart applications.
  • Cluster Mode: Scale apps across all CPU cores without code changes.
  • Auto-Restart: Automatically restarts apps on crash or system reboot.
  • Real-time Monitoring: Track CPU and Memory usage via CLI.
  • Log Management: Consolidated log streaming and flushing.

I personally utilize it primarily for managing processes and logging, allowing you to start, stop, and automatically restart Node.js processes.

💻 Here's a list of commonly used PM2 commands along with examples:

Starting Applications

Task Command
Start a basic Node app pm2 start app.js
Start Next.js with a name pm2 start npm --name "app-name" -- start
Start and watch for changes pm2 start app.js --watch

Monitoring & Status

Task Command
List all processes pm2 ls
Show app details pm2 show <app-name>
Real-time Dashboard pm2 monit
View Logs pm2 logs <app-name>

Managing Life Cycle

Task Command
Stop a process pm2 stop <app-name>
Restart a process pm2 restart <app-name>
Zero-Downtime Reload pm2 reload <app-name>
Delete from list pm2 delete <app-name>
Clear logs pm2 flush <app-name>

Persistence (Server Reboots)

Task Command
Save current process list pm2 save
Generate startup script pm2 startup

These commands should cover most of the common tasks you need to perform when working with PM2. For more detailed information, you can always refer to the official PM2 documentation.


📺 Deployment Tutorials

If you're deploying a Next.js site from scratch on Ubuntu with NGINX, these guides are highly recommended:

🔗 References

Top comments (0)