PM2 is a production process manager for Node.js/Bun applications with a built-in load balancer. It allows you to keep applications alive forever, to reload them without downtime and to facilitate common system admin tasks.
Starting an application in production mode is as easy as:
$ pm2 start app.jsPM2 is constantly assailed by more than 1800 tests.
Official website: https://pm2.keymetrics.io/
Works on Linux (stable) & macOS (stable) & Windows (stable). All Node.js versions are supported starting Node.js 22.0.0 and Bun since v1
$ npm install pm2 -g$ bun install pm2 -gPlease note that you might need to symlink node to bun if you only want to use bun via sudo ln -s /home/$USER/.bun/bin/bun /usr/bin/node
You can install Node.js easily with NVM or FNM or install Bun with curl -fsSL https://bun.sh/install | bash
You can start any application (Node.js, Bun, and also Python, Ruby, binaries in $PATH...) like that:
$ pm2 start app.jsYour app is now daemonized, monitored and kept alive forever.
Once applications are started you can manage them easily:
To list all running applications:
$ pm2 listManaging 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 monitThe Cluster mode is a special mode when starting a Node.js application, it starts multiple processes and load-balance HTTP/TCP/UDP queries between them. This increase overall performance (by a factor of x10 on 16 cores machines) and reliability (faster socket re-balancing in case of unhandled errors).
Starting a Node.js application in cluster mode that will leverage all CPUs available:
$ pm2 start api.js -i <processes><processes> can be 'max', -1 (all cpu minus 1) or a specified number of instances to start.
Zero Downtime Reload
Hot Reload allows to update an application without any downtime:
$ pm2 reload allMore informations about how PM2 make clustering easy
With the drop-in replacement command for node, called pm2-runtime, run your Node.js application in a hardened production environment.
Using it is seamless:
RUN npm install pm2 -g
CMD [ "pm2-runtime", "npm", "--", "start" ]
Read More about the dedicated integration
PM2 allows to monitor your host/server vitals with a monitoring speedbar.
To enable host monitoring:
$ pm2 set pm2:sysmonit true
$ pm2 updateMonitor all processes launched straight from the command line:
$ pm2 monitTo consult logs just type the command:
$ pm2 logsStandard, Raw, JSON and formated output are available.
Examples:
$ pm2 logs APP-NAME # Display APP-NAME logs
$ pm2 logs --json # JSON output
$ pm2 logs --format # Formated output
$ pm2 flush # Flush all logs
$ pm2 reloadLogs # Reload all logsTo enable log rotation install the following module
$ pm2 install pm2-logrotatePM2 can generate and configure a Startup Script to keep PM2 and your processes alive at every server restart.
Init Systems Supported: systemd, upstart, launchd, rc.d
# Generate Startup Script
$ pm2 startup
# Freeze your process list across server restart
$ pm2 save
# Remove Startup Script
$ pm2 unstartupMore about Startup Scripts Generation
# Install latest PM2 version
$ npm install pm2@latest -g
# Save process list, exit old PM2 & restore all processes
$ pm2 updatePM2 updates are seamless
PM2 now bundles an MCP stdio server that exposes the core process controls (list, describe, start, restart, reload, stop, delete, log flush/rotation, dump, daemon kill) plus process resources.
# Add pm2-mcp to Claude Code
claude mcp add pm2-mcp -- pm2-mcp
# Verify it's connected
claude mcp list
# Get details
claude mcp get pm2-mcp# Add pm2-mcp to Codex
codex mcp add pm2-mcp -- pm2-mcp
# Verify registration
codex mcp list# Start HTTP server
pm2-mcp --transport http --port 8849 --host 127.0.0.1 --path /mcp
# Or with PM2 to keep it alive
pm2-mcp --pm2 --pm2-name mcp-server --transport http --port 8849
# Register with Claude Code (HTTP)
claude mcp add pm2-mcp --transport http -- http://127.0.0.1:8849/mcp
# Register with Codex (HTTP)
codex mcp add pm2-mcp --transport http -- http://127.0.0.1:8849/mcp| Variable | Default | Description |
|---|---|---|
PM2_HOME |
~/.pm2 |
PM2 home directory for sockets/logs |
PM2_MCP_HOME |
- | Override PM2_HOME specifically for MCP server |
PM2_MCP_TRANSPORT |
stdio |
Transport type: stdio, http, sse, streamable |
PM2_MCP_PORT |
8849 |
Port for HTTP/SSE transport |
PM2_MCP_HOST |
127.0.0.1 |
Host for HTTP/SSE transport |
PM2_MCP_PATH |
/mcp |
Path for HTTP/SSE transport |
PM2_MCP_NO_DAEMON |
true |
Use PM2 no-daemon mode (recommended for sandboxed clients) |
PM2_SILENT |
true |
Silence PM2 CLI output for clean stdio |
PM2_PROGRAMMATIC |
true |
Run PM2 in programmatic mode |
PM2_MCP_DEBUG |
false |
Enable debug logging (sandbox detection, transport info) |
PM2_MCP_ALLOWED_HOSTS |
- | Comma-separated list of allowed hosts for HTTP transport |
PM2_MCP_ALLOWED_ORIGINS |
- | Comma-separated list of allowed origins for HTTP transport |
PM2_MCP_DNS_PROTECTION |
true |
Enable DNS rebinding protection |
DEBUG |
- | Node.js debug namespace: pm2-mcp* for all logs, pm2-mcp:req for requests |
CLAUDE_CODE_SANDBOX |
- | Set to true to indicate Claude Code sandbox environment |
The MCP server automatically detects sandboxed environments and adapts:
- Home Directory Check: Tests if
~/.pm2is writable - Environment Detection: Checks for
CLAUDE_CODE_SANDBOX=true - Permission Detection: Detects UID mismatches (setuid)
- Fallback Locations: Automatically tries
/tmp/pm2-mcpand./.pm2-mcpin sandboxed environments - Client Notifications: Sends MCP logging notifications to clients when sandbox is detected
When running in a sandboxed environment, the server will:
- Automatically use a writable location for PM2_HOME
- Send a warning notification to the MCP client with:
- Sandbox detection reasons
- Current PM2_HOME location
- Recommendations for optimal configuration
- Log sandbox status (when
PM2_MCP_DEBUG=true)
Enable PM2_MCP_DEBUG=true to see sandbox detection details:
DEBUG=pm2-mcp* PM2_MCP_DEBUG=true pm2-mcpMCP Protocol Support: The server uses the MCP notifications/message logging protocol to inform clients about sandbox status and limitations. Compatible MCP clients (like Claude Code) will display these notifications automatically.
- Run it with
pm2-mcp(ornpm run mcp) and point your MCP client at that stdio command. - Prefer the Streamable HTTP transport for long-lived usage.
- By default the server starts in PM2 no-daemon mode for compatibility with sandboxed MCP clients. Set
PM2_MCP_NO_DAEMON=falseto connect to an existing PM2 daemon instead. - PM2 CLI noise is silenced automatically to keep stdio clean for the MCP handshake; set
PM2_SILENT=falseonly if you need PM2 console output. - Run the server under PM2 itself with
pm2-mcp --pm2 --pm2-name mcp-server --transport http --port 8849to keep it alive across restarts. - Logging: set
DEBUG=pm2-mcp*to see lifecycle/activity logs (transport selection, PM2 connects, tool calls).
pm2_list_processes- List all PM2 processes with basic metricspm2_describe_process- Get detailed process informationpm2_start_process- Start a new process or ecosystem filepm2_restart_process- Restart a process by id/namepm2_reload_process- Zero-downtime reload (cluster mode)pm2_stop_process- Stop a process by id/namepm2_delete_process- Delete a process from PM2pm2_flush_logs- Flush log files for a processpm2_reload_logs- Rotate and reopen log filespm2_dump- Save process list to diskpm2_tail_logs- Read last N lines from process logspm2_kill_daemon- Stop PM2 daemon and all processes
pm2://processes- Current PM2 process list as JSONpm2://process/{id}- Detailed process information as JSON
If you manage your apps with PM2, PM2+ makes it easy to monitor and manage apps across servers.
Feel free to try it:
Discover the monitoring dashboard for PM2
Thanks in advance and we hope that you like PM2!
PM2 is made available under the terms of the GNU Affero General Public License 3.0 (AGPL 3.0). For other licenses contact us.





