PM2 Cheatsheet - Node.js Process Manager Reference
All essential PM2 commands organized by use case, with 38+ entries you can copy and run directly. Find the right command fast when you need it.
Back to LanguagesStart & Stop 12
pm2 start app.jsStart应用
pm2 start app.js --name "api"Start&命名Process
pm2 start app.js -i max集群模式,按 CPU 核数Start
pm2 start app.js -i 4集群模式,指定 4 个Process
pm2 start ecosystem.config.js用ConfigureFileStart(recommended)
pm2 stop allStop所有Process
pm2 stop apiStop指定Process
pm2 restart apiRestartProcess(重载代码)
pm2 reload api零停机重载(集群模式recommended)
pm2 delete api从ProcesslistDelete
pm2 start app.js --watch监听File变化自动Restart
pm2 kill杀掉所有Process&Stop PM2 守护
Logs 5
pm2 logsReal-time view of所有日志
pm2 logs api --lines 100Show指定Process最近 100 行
pm2 logs api --err只看错误日志
pm2 flush清空所有日志File
pm2 install pm2-logrotateInstall日志轮转module,防止日志无限增长
Monitor 6
pm2 listList所有Process
pm2 show apiShowProcess详情
pm2 monit终端监控面板(CPU/Memory)
pm2 statusShowProcessstate
pm2 describe apiShowProcessverbose描述信息
pm2 jlistJSON 格式OutputProcesslist(适合脚本)
Startup 4
pm2 startup生成enable on boot脚本,按promptExecuteOutput的命令
pm2 saveSave当前Processlist,enable on boot时restore
pm2 resurrect手动restoreSave的Processlist
pm2 unstartupRemoveenable on boot
Cluster & Scale 5
pm2 scale api +2扩容 2 个Process
pm2 scale api 8指定Process总数为 8
pm2 reset api重置ProcessRestart计数
pm2 serve ./dist 8080静态FileDirectoryService
pm2 deploy ecosystem.config.js production通过ConfigureFiledeploy到远程
Ecosystem Config (ecosystem.config.js) 6
module.exports = { apps: [{ name: "api", script: "app.js", instances: "max", exec_mode: "cluster" }] }基础集群Configure
env: { NODE_ENV: "production", PORT: 3000 }env varConfigure
max_memory_restart: "1G"Memory超 1G 自动Restart
error_file: "./logs/err.log", out_file: "./logs/out.log"自定义日志路径
watch: true, ignore_watch: ["node_modules", "logs"]File变化自动Restart
pm2 start ecosystem.config.js --env production指定环境Start(Read env_production)
💡 Tips
- reload 比 restart 更平滑,集群模式下逐个重启实现零停机,单进程模式 reload 等同于 restart。
- pm2 save + pm2 startup 组合实现开机自启,服务器重启后自动恢复所有进程。
- 内存泄漏排查:pm2 monit 观察内存趋势,配置 max_memory_restart 自动重启兜底。
Official References
Commands are compiled from the official docs below. Click to verify the latest usage.
Maintained by LaoHand
Publicly updated on Jul 21, 2026, continuously proofread against official docs.
Found an error? Report it
Wrong command or description? Open an issue to help us fix it.
Found an error? Report it