pm2
Node.js Production Process Manager with a built-in Load Balancer.
Installation
With NPM:
npm install pm2 -g
Startup Scripts Generation
PM2 can generate and configure a Startup Script to keep PM2 and your processes alive at every server restart.
# Generate Startup Script
pm2 startup
# Freeze your process list across server restart
pm2 save
# Remove Startup Script
pm2 unstartup
Updating PM2
# Install latest PM2 version
npm install pm2@latest -g
# Save process list, exit old PM2 & restore all processes
pm2 update
Start an application
You can start any application (Node.js, Python, Ruby, binaries in $PATH…) like that:
pm2 start app.js
Managing Applications
To list all running applications:
pm2 list
Managing apps is straightforward:
pm2 stop <app_name|namespace|id|'all'|json_conf>
pm2 restart <app_name|namespace|id|'all'|json_conf>
pm2 delete <app_name|namespace|id|'all'|json_conf>
To have more details on a specific application:
pm2 describe <id|app_name>
To monitor logs, custom metrics, application information:
pm2 monit
Cluster Mode: Node.js Load Balancing & Zero Downtime Reload
Starting a Node.js application in cluster mode that will leverage all CPUs available:
# <processes> can be 'max', -1 (all cpu minus 1) or a specified number of instances to start.
pm2 start api.js -i <processes>
Hot Reload allows to update an application without any downtime:
pm2 reload all