Hi everyone, TM here! π
Today Iβm sharing a complete PM2 Cheatsheet that I personally use for managing Node.js apps in production.
Unlike traditional setups like PHP (which runs behind Apache or Nginx) or Python (which often uses servers like Gunicorn or uWSGI), Node.js apps donβt come with a built-in process manager.
You have to handle starting, restarting, and keeping your app alive manually β unless you use a tool like PM2.
PM2 fills that gap perfectly.
It keeps your Node.js apps running 24/7, auto-restarts after crashes, helps with scaling across CPU cores, and makes deployment super clean.
This cheatsheet covers everything you need β from basic commands to startup scripts and ecosystem files β in a simple, developer-friendly format.
Letβs dive in!
PM2 is a powerful production process manager for Node.js applications. Whether youβre running a single app or managing a fleet of services, PM2 gives you the tools to keep your code running smoothly, monitor performance, and reboot on failure β all with just a few commands.
π§ Installation
npm install -g pm2
βοΈ Basic Commands
Command | Description |
---|---|
pm2 start app.js | Start an app |
pm2 list | List all running apps |
pm2 stop <name> | Stop an app |
pm2 restart <name> | Restart an app |
pm2 delete <name> | Remove an app from PM2 |
pm2 monit | Monitor live app performance |
π Start with Options
pm2 start app.js --name myapp # Custom name
pm2 start app.js -i max # Cluster mode (multi-core)
pm2 start app.js --watch # Auto-restart on file changes
pm2 start app.js --ignore-watch="node_modules logs" # Ignore folders
π Process Management
Command | Purpose |
---|---|
pm2 reload all | Graceful restart all |
pm2 gracefulReload <name> | Graceful single restart |
pm2 restart all | Hard restart all apps |
pm2 delete all | Remove all from PM2 list |
π Auto-Start on Reboot
pm2 startup # Generate startup script
pm2 save # Save current process list
To remove startup script:
pm2 unstartup
π Ecosystem File (for Multi-App Management)
Create ecosystem.config.js:
module.exports = {
apps: [
{
name: 'myapp',
script: './app.js',
watch: true,
instances: 'max',
exec_mode: 'cluster',
env: {
NODE_ENV: 'development'
},
env_production: {
NODE_ENV: 'production'
}
}
]
};
Launch with:
pm2 start ecosystem.config.js
π Logs & Debugging
pm2 logs # View all logs
pm2 logs <name> # View logs for specific app
pm2 flush # Clear logs
pm2 reloadLogs # Reload logs
Logs location: ~/.pm2/logs/
π§ PM2 Fun Facts
- PM2 stands for Process Manager 2.
- Works with any language (with interpreter defined).
- Runs in the background as a daemon.
- Built in Node.js, supports real-time monitoring.
- Supports JSON config for scalable deployment.
πΊ Bonus: Visual Map
Want a birdβs-eye view? Hereβs a mind map image to understand the full PM2 workflow at a glance.

β Conclusion
PM2 is your secret weapon for keeping your Node.js apps alive and optimized in production. Whether youβre deploying a single app or managing a fleet of services, it makes process management a breeze.
Save this cheatsheet, and run your apps like a pro.