
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 apppm2 start app.js# Start with a name (way easier to manage)pm2 start app.js --name "api"# Start a Next.js or npm scriptpm2 start npm --name "web" -- start# Cluster mode (use all CPU cores)pm2 start app.js -i max
Checking Status
# List all running appspm2 list# Detailed info on one apppm2 show api# Real-time dashboardpm2 monit
Logs
# All logspm2 logs# Logs for specific apppm2 logs api# Last 100 linespm2 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 appspm2 restart all
Stopping and Deleting
# Stop (keeps in list)pm2 stop api# Delete (removes completely)pm2 delete api# Nuclear optionpm2 delete all
Saving and Startup
# Save current process listpm2 save# Set PM2 to start on server rebootpm2 startup
Key Takeaways
- Name applications with
--namefor easier management - Prefer
reloadoverrestartfor zero-downtime deployments - Execute
pm2 saveafter modifications to ensure persistence - Monitor performance using
pm2 monitwhen troubleshooting slowness - Keep this reference accessible for 2 AM emergency situations