DEV Community

Cover image for Open Source Process Manager for Node.js
VORG
VORG

Posted on • Updated on

Open Source Process Manager for Node.js

PM2

Star 36.4k Watch 667 Fork 2.4k

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.

PM2 is constantly assailed by more than 1800 tests.

Official website

Works on Linux (stable) & macOS (stable) & Windows (stable). All Node.js versions are supported starting Node.js 12.X.

Managing Applications

Once applications are started you can manage them easily:
Image description
To list all running applications:

$ pm2 list
Enter fullscreen mode Exit fullscreen mode

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>
Enter fullscreen mode Exit fullscreen mode

To have more details on a specific application:

$ pm2 describe <id|app_name>
Enter fullscreen mode Exit fullscreen mode

To monitor logs, custom metrics, application information:

$ pm2 monit
Enter fullscreen mode Exit fullscreen mode

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).
Image description

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

$ pm2 start api.js -i <processes>
Enter fullscreen mode Exit fullscreen mode

<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 all
Enter fullscreen mode Exit fullscreen mode

Host monitoring speedbar

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

To enable host monitoring:

$ pm2 set pm2:sysmonit true
$ pm2 update
Enter fullscreen mode Exit fullscreen mode

Image description

Terminal Based Monitoring

Image description
Monitor all processes launched straight from the command line:

$ pm2 monit
Enter fullscreen mode Exit fullscreen mode

PM2+ Monitoring

If you manage your apps with PM2, PM2+ makes it easy to monitor and manage apps across servers.
Image description
Feel free to try it:
Discover the monitoring dashboard for PM2
Thanks in advance and we hope that you like PM2!

License

PM2 is made available under the terms of the GNU Affero General Public License 3.0 (AGPL 3.0).

Discussion (0)