Node.js › Deployment & Process Managers (PM2)

What problem does PM2 solve for running a Node.js application in production, beyond just executing 'node server.js'?

Beginner

Answer

Running 'node server.js' directly leaves the process with no automatic restart if it crashes, no built-in way to run multiple instances across CPU cores, no persistent log management, and it stops entirely if the terminal session ends -- PM2 is a production process manager that handles automatic restarts on crash, clustering across cores, log file management and rotation, and keeps the application running detached from any specific terminal session, persisting across SSH disconnects and (with setup) system reboots.
npm install -g pm2

pm2 start server.js --name my-app
pm2 list          # view running processes
pm2 logs my-app    # tail logs
pm2 restart my-app
pm2 stop my-app
Real-world example A team that previously ran their Node.js API with 'node server.js' inside a tmux session (which occasionally crashed silently overnight, going unnoticed until customers complained) switches to PM2, which automatically restarts the process within seconds of any crash and keeps a searchable log history of exactly what happened each time.

Common follow-ups: How does PM2 differ from using a systemd service to achieve similar restart-on-crash behavior?;What's the risk of relying solely on PM2's auto-restart without also investigating why the process crashed in the first place?