Privacy Policy
Sun Dec 14
05:19

About

Blog

Github

GitHub

Github

YouTube

Github

Instagram

LinkedIn

LinkedIn

~/Users/jan/blog/pm2-commands-cheat-sheet

back

Quick PM2 Commands You'll Use Daily

PM2 Commands Cheat Sheet
PM2 Commands Cheat Sheet

A concise reference guide covering the essential PM2 commands for managing Node.js applications in production environments, presented without unnecessary complexity.

PM2 offers numerous commands, but daily operations typically require only about ten. This resource compiles the most frequently referenced commands.

Starting Apps

# Start an app
pm2 start app.js
# Start with a name (way easier to manage)
pm2 start app.js --name "api"
# Start a Next.js or npm script
pm2 start npm --name "web" -- start
# Cluster mode (use all CPU cores)
pm2 start app.js -i max

Checking Status

# List all running apps
pm2 list
# Detailed info on one app
pm2 show api
# Real-time dashboard
pm2 monit

Logs

# All logs
pm2 logs
# Logs for specific app
pm2 logs api
# Last 100 lines
pm2 logs api --lines 100
# Clear all log files (they get big)
pm2 flush

Restarting and Reloading

# Hard restart (brief downtime)
pm2 restart api
# Graceful reload (zero downtime, cluster mode only)
pm2 reload api
# Restart all apps
pm2 restart all

Stopping and Deleting

# Stop (keeps in list)
pm2 stop api
# Delete (removes completely)
pm2 delete api
# Nuclear option
pm2 delete all

Saving and Startup

# Save current process list
pm2 save
# Set PM2 to start on server reboot
pm2 startup

Key Takeaways

  • Name applications with --name for easier management
  • Prefer reload over restart for zero-downtime deployments
  • Execute pm2 save after modifications to ensure persistence
  • Monitor performance using pm2 monit when troubleshooting slowness
  • Keep this reference accessible for 2 AM emergency situations