PM2 basics
PM2 keeps your Node app running, restarts it if it crashes and can run several copies.
In this page:
Syntax
pm2 start app.js
pm2 list
pm2 restart app
pm2 stop app
PM2 basics
PM2 is a process manager. pm2 start app.js runs the app in the background, pm2 list shows status, pm2 logs streams output and pm2 restart applies changes. Cluster mode runs one process per CPU core and an ecosystem file records settings.
Note:
Use pm2 startup and pm2 save to restart apps after a reboot.
Example: PM2 basics
$ npm install -g pm2
$ pm2 start app.js -i max --name api
$ pm2 list
$ pm2 logs api
$ pm2 save && pm2 startup
⚠️ Run this in your own terminal or Node.js environment.
Related Topics
Common Mistakes
- Running node directly on a server
- Not saving the process list
- Ignoring log rotation
Chapter Summary
- PM2 restarts crashed apps
- start, list, logs, restart
- Cluster mode uses all cores
- Ecosystem files store config
🔒
Chapter Quiz — Complete all 7 topics to unlock
0/7 topics done
Complete these topics first: