PM2

Node.js Production Process Manager with a built-in Load Balancer.

README


pm2 logo

P(rocess) M(anager) 2
Runtime Edition

Downloads per Month Downloads per Year npm version Build Status




PM2 is a production process manager for Node.js 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:

  1. ``` sh
  2. $ pm2 start app.js
  3. ```

PM2 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 12.X.


Installing PM2


With NPM:

  1. ``` sh
  2. $ npm install pm2 -g
  3. ```

You can install Node.js easily with NVM or ASDF.

Start an application


You can start any application (Node.js, Python, Ruby, binaries in $PATH...) like that:

  1. ``` sh
  2. $ pm2 start app.js
  3. ```

Your app is now daemonized, monitored and kept alive forever.

Managing Applications


Once applications are started you can manage them easily:

Process listing

To list all running applications:

  1. ``` sh
  2. $ pm2 list
  3. ```

Managing apps is straightforward:

  1. ``` sh
  2. $ pm2 stop     <app_name|namespace|id|'all'|json_conf>
  3. $ pm2 restart  <app_name|namespace|id|'all'|json_conf>
  4. $ pm2 delete   <app_name|namespace|id|'all'|json_conf>
  5. ```

To have more details on a specific application:

  1. ``` sh
  2. $ pm2 describe <id|app_name>
  3. ```

To monitor logs, custom metrics, application information:

  1. ``` sh
  2. $ pm2 monit
  3. ```


Cluster Mode: Node.js Load Balancing & Zero Downtime Reload


The 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).

Framework supported

Starting a Node.js application in cluster mode that will leverage all CPUs available:

  1. ``` sh
  2. $ pm2 start api.js -i <processes>
  3. ```

`` 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:

  1. ``` sh
  2. $ pm2 reload all
  3. ```


Container Support


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:

  1. ```
  2. RUN npm install pm2 -g
  3. CMD [ "pm2-runtime", "npm", "--", "start" ]
  4. ```


Host monitoring speedbar


PM2 allows to monitor your host/server vitals with a monitoring speedbar.

To enable host monitoring:

  1. ``` sh
  2. $ pm2 set pm2:sysmonit true
  3. $ pm2 update
  4. ```

Framework supported

Terminal Based Monitoring


Monit

Monitor all processes launched straight from the command line:

  1. ``` sh
  2. $ pm2 monit
  3. ```

Log Management


To consult logs just type the command:

  1. ``` sh
  2. $ pm2 logs
  3. ```

Standard, Raw, JSON and formated output are available.

Examples:

  1. ``` sh
  2. $ pm2 logs APP-NAME       # Display APP-NAME logs
  3. $ pm2 logs --json         # JSON output
  4. $ pm2 logs --format       # Formated output

  5. $ pm2 flush               # Flush all logs
  6. $ pm2 reloadLogs          # Reload all logs
  7. ```

To enable log rotation install the following module

  1. ``` sh
  2. $ pm2 install pm2-logrotate
  3. ```


Startup Scripts Generation


PM2 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

  1. ``` sh
  2. # Generate Startup Script
  3. $ pm2 startup

  4. # Freeze your process list across server restart
  5. $ pm2 save

  6. # Remove Startup Script
  7. $ pm2 unstartup
  8. ```


Updating PM2


  1. ``` sh
  2. # Install latest PM2 version
  3. $ npm install pm2@latest -g
  4. # Save process list, exit old PM2 & restore all processes
  5. $ pm2 update
  6. ```

PM2 updates are seamless

PM2+ Monitoring


If you manage your apps with PM2, PM2+ makes it easy to monitor and manage apps across servers.

https://app.pm2.io/

Feel free to try it:


Thanks in advance and we hope that you like PM2!

CHANGELOG



Contributors



License


PM2 is made available under the terms of the GNU Affero General Public License 3.0 (AGPL 3.0).
For other licenses contact us.