Spring Fresh Sale! - Up To 67% OFF BDIX Hosting + Free Domain
Node.js

How to Run Node.js in Production with PM2: Clustering and Zero-Downtime Reloads

PM2 is a process manager that keeps your Node.js app running, restarts it if it crashes, scales it across CPU cores, and reloads new code with zero downtime. For running Node in production on a VPS, it is the standard tool — and it removes most of the manual work of clustering and uptime.

Installing and starting

npm install -g pm2
pm2 start app.js --name myapp

Your app now runs in the background, and PM2 restarts it automatically if it crashes.

Clustering across cores

PM2's cluster mode runs multiple instances that share a port, using every CPU core — no manual cluster module code needed:

pm2 start app.js -i max

-i max launches one instance per core. Remember each instance has its own memory, so keep shared state in Redis.

Zero-downtime reloads

When you deploy new code, reload instead of restart so users see no interruption:

pm2 reload myapp

PM2 restarts instances one at a time, keeping the app serving throughout — which works best when your app supports graceful shutdown.

Surviving server reboots

Make PM2 restart your apps on boot:

pm2 startup then pm2 save

Monitoring

pm2 list shows status, pm2 logs streams logs, and pm2 monit gives a live dashboard — a good complement to full production monitoring. An alternative to PM2 is a systemd service.

Frequently asked questions

What's the difference between restart and reload?

restart stops and starts (brief downtime); reload in cluster mode replaces instances one by one for zero downtime. Use reload for deploys when running clustered.

Do I still need the cluster module with PM2?

No — PM2 cluster mode handles the forking for you. Write your app as a single instance and let PM2 scale it with -i.

Does PM2 work on shared hosting?

It needs persistent process control, which shared cPanel usually restricts. On a VPS or on Webuzo (with SSH) it works well — see keeping Node running on Webuzo with PM2.

Was this article helpful?