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.

Languages·38 commands·Last updated 2026-07-21
Back to Languages

Start & Stop 12

pm2 start app.js
Start应用
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 all
Stop所有Process
pm2 stop api
Stop指定Process
pm2 restart api
RestartProcess(重载代码)
pm2 reload api
零停机重载(集群模式recommended)
pm2 delete api
从ProcesslistDelete
pm2 start app.js --watch
监听File变化自动Restart
pm2 kill
杀掉所有Process&Stop PM2 守护

Logs 5

pm2 logs
Real-time view of所有日志
pm2 logs api --lines 100
Show指定Process最近 100 行
pm2 logs api --err
只看错误日志
pm2 flush
清空所有日志File
pm2 install pm2-logrotate
Install日志轮转module,防止日志无限增长

Monitor 6

pm2 list
List所有Process
pm2 show api
ShowProcess详情
pm2 monit
终端监控面板(CPU/Memory)
pm2 status
ShowProcessstate
pm2 describe api
ShowProcessverbose描述信息
pm2 jlist
JSON 格式OutputProcesslist(适合脚本)

Startup 4

pm2 startup
生成enable on boot脚本,按promptExecuteOutput的命令
pm2 save
Save当前Processlist,enable on boot时restore
pm2 resurrect
手动restoreSave的Processlist
pm2 unstartup
Removeenable 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