PM2 is the standard process manager for Node.js in production. This guide covers installation, starting apps, auto-restart on crash, cluster mode for multi-core CPUs, log management, and startup on reboot.
In this guide
Install globally: npm install -g pm2. Verify: pm2 --version. PM2 is a daemon process manager that keeps your Node.js apps running in the background, automatically restarts them on crash, and provides log aggregation. It is the most widely used solution for Node.js production deployments.
Navigate to your app directory and run: pm2 start npm --name "myapp" -- start. Or to run a file directly: pm2 start server.js --name "myapp". List running processes: pm2 list. Check logs: pm2 logs myapp. Restart: pm2 restart myapp. Stop: pm2 stop myapp. Delete from PM2: pm2 delete myapp.
Run: pm2 startup — this outputs a command specific to your system (usually a systemd command). Copy and run that command as instructed. Then: pm2 save — this saves the current process list to ~/.pm2/dump.pm2. On server reboot, the systemd service restores all saved processes automatically. Run pm2 save after any change to your process list.
Node.js is single-threaded by default. PM2 cluster mode spawns one worker per CPU core: pm2 start server.js -i max --name "myapp". All workers share the same port — PM2 load balances between them. This multiplies throughput on multi-core servers. Use pm2 reload myapp (not restart) for zero-downtime updates in cluster mode.
Create ecosystem.config.js: module.exports = { apps: [{ name: "myapp", script: "./server.js", instances: "max", exec_mode: "cluster", env: { NODE_ENV: "production", PORT: 3000 } }] }. Start with: pm2 start ecosystem.config.js. This keeps your PM2 config in version control and makes deployments repeatable. Store environment variables here instead of passing them on the command line.
PM2 logs grow indefinitely by default. Install log rotation: pm2 install pm2-logrotate. Configure it: pm2 set pm2-logrotate:max_size 100M — pm2 set pm2-logrotate:retain 7 — pm2 set pm2-logrotate:compress true. This rotates logs when they hit 100MB and keeps 7 days of history. Without this, logs will eventually fill your disk.
Need Help?
Our engineering team handles implementations like this every week. Get a free scoping call — we will tell you exactly what it takes and what it costs.
Book a free callCompetitive Intelligence
Efficiency Modeling
© 2026 NexWorldTech — Built for Global Dominance.