📖 Guide
PM2 — Complete Reference
Production process manager for Node.js — process management, cluster mode, monitoring, logs, deployment, and ecosystem configuration.
53 commands across 8 categories
Process ManagementMonitoringCluster ModeLogsStartup ScriptsConfiguration (ecosystem.config.js)DeployCommon Patterns
Process Management
| Command | Description |
|---|---|
pm2 start app.js | Start an application |
pm2 start app.js --name my-app | Start with a custom name |
pm2 stop my-app | Stop a process by name or id |
pm2 restart my-app | Restart a process |
pm2 reload my-app | Zero-downtime reload (for networked apps) |
pm2 delete my-app | Remove process from PM2 list |
pm2 start app.js --watch | Start and watch for file changes |
pm2 start app.js -- --port 3000 | Pass arguments to the script (after --) |
Monitoring
| Command | Description |
|---|---|
pm2 list | List all running processes |
pm2 monit | Open real-time monitoring dashboard |
pm2 show my-app | Show detailed info about a process |
pm2 status | Alias for pm2 list |
pm2 prettylist | List processes in JSON format (pretty-printed) |
pm2 jlist | List processes as raw JSON |
pm2 describe 0 | Show full metadata for process id 0 |
Cluster Mode
| Command | Description |
|---|---|
pm2 start app.js -i max | Start in cluster mode with max CPUs |
pm2 start app.js -i 4 | Start with 4 cluster instances |
pm2 scale my-app +2 | Add 2 more instances to a cluster |
pm2 scale my-app 6 | Scale cluster to exactly 6 instances |
pm2 reload my-app | Zero-downtime reload all cluster instances |
pm2 start app.js -i -1 | Start with max CPUs minus 1 |
Logs
| Command | Description |
|---|---|
pm2 logs | Stream logs from all processes |
pm2 logs my-app | Stream logs for a specific process |
pm2 logs --lines 200 | Show last 200 lines of logs |
pm2 flush | Clear all log files |
pm2 reloadLogs | Reload all log streams (for log rotation) |
pm2 logs my-app --err | Show only error logs |
pm2 install pm2-logrotate | Install log rotation module |
Startup Scripts
| Command | Description |
|---|---|
pm2 startupe.g. pm2 startup systemd | Generate startup script for current OS |
pm2 save | Save current process list for auto-restart |
pm2 unstartup | Remove the startup script |
pm2 resurrect | Manually restore previously saved processes |
pm2 save --force | Force save (overwrite existing dump) |
Configuration (ecosystem.config.js)
| Command | Description |
|---|---|
pm2 init simple | Generate a simple ecosystem.config.js file |
pm2 start ecosystem.config.js | Start all apps defined in config |
pm2 start ecosystem.config.js --only my-app | Start only a specific app from config |
pm2 start ecosystem.config.js --env production | Start with production environment variables |
module.exports = { apps: [{ name: 'api', script: './api.js', instances: 4, exec_mode: 'cluster' }] } | Ecosystem config with cluster mode |
env_production: { NODE_ENV: 'production', PORT: 3000 } | Define environment-specific variables in config |
Deploy
| Command | Description |
|---|---|
pm2 deploy production setup | Setup remote deployment target |
pm2 deploy production | Deploy to production |
pm2 deploy production revert 1 | Revert to previous deployment |
pm2 deploy production curr | Show current deployed commit |
pm2 deploy production list | List previous deployments |
pm2 deploy production exec 'pm2 reload all' | Execute a command on remote host |
Common Patterns
| Command | Description |
|---|---|
pm2 start npm -- start | Run npm start as a PM2 process |
pm2 start npx -- serve -s build | Run npx command under PM2 |
pm2 start app.js --max-memory-restart 300M | Auto-restart if memory exceeds 300MB |
pm2 start app.js --cron-restart='0 */4 * * *' | Restart on a cron schedule (every 4 hours) |
pm2 start app.js --exp-backoff-restart-delay=100 | Exponential backoff on crash restarts |
pm2 start app.py --interpreter python3 | Run a Python script with PM2 |
pm2 start app.js --no-autorestart | Start without automatic restart on crash |
pm2 kill | Kill the PM2 daemon and all processes |
📖 Free, searchable command reference. Bookmark this page for quick access.