gitmyhub

pm2

JavaScript ★ 4 updated 12y ago ⑂ fork

The modern CLI process manager for Node apps with native clusterization

A command-line process manager that keeps Node.js apps running, auto-restarting crashes and load-balancing across CPU cores.

Node.jsJavaScriptsetup: easycomplexity 2/5

PM2: Keep Your Node Apps Running

PM2 is a command-line tool that manages Node.js applications for you. Think of it like a personal assistant for your server—it starts your apps, watches them 24/7, restarts them if they crash, and keeps detailed logs of what's happening. The main benefit is that your applications stay online reliably, even when unexpected errors occur.

At its core, PM2 handles three things that would otherwise require manual work. First, it runs multiple copies of your app across available CPU cores, which makes it handle more traffic without needing to rewrite your code. Second, it automatically restarts any process that fails or exits unexpectedly, so downtime is minimal. Third, it gives you real-time visibility into what your apps are doing—you can see CPU and memory usage in a terminal dashboard, stream live logs, and even get an API endpoint that reports on your server's health.

A typical user might be someone deploying a Node.js web server or API to production. Instead of manually starting the app and hoping it stays up, they'd run a single command like pm2 start app.js -i max to launch multiple instances across all CPU cores, then use pm2 monit to watch CPU and memory in real time. If the process crashes, PM2 brings it back up automatically. You can also define complex setups in a JSON file—launching multiple different Node apps with different configurations all at once—and save the state so that if your server reboots, PM2 resurrects all your processes automatically.

The README emphasizes that this is a "modern and stable" tool tested across several Node versions on Linux and macOS. It covers real production needs: log aggregation, scheduled restarts via cron patterns, dumping and restoring process state, and a web API for monitoring. It's designed to be the kind of tool you install once and then mostly forget about because your apps just keep running.

Where it fits