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:
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).
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:
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:
P(rocess) M(anager) 2
Runtime Edition
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 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 and Bun since v1
Installing PM2
With NPM
With Bun
Please 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/nodeYou can install Node.js easily with NVM or FNM or install Bun with
curl -fsSL https://bun.sh/install | bashStart an application
You can start any application (Node.js, Bun, and also Python, Ruby, binaries in $PATH…) like that:
Your app is now daemonized, monitored and kept alive forever.
Managing Applications
Once applications are started you can manage them easily:
To list all running applications:
Managing apps is straightforward:
To have more details on a specific application:
To monitor logs, custom metrics, application information:
More about Process Management
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).
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.Zero Downtime Reload
Hot Reload allows to update an application without any downtime:
More informations about how PM2 make clustering easy
Container Support
With the drop-in replacement command for
node, calledpm2-runtime, run your Node.js application in a hardened production environment. Using it is seamless:Read More about the dedicated integration
Host monitoring speedbar
PM2 allows to monitor your host/server vitals with a monitoring speedbar.
To enable host monitoring:
Terminal Based Monitoring
Monitor all processes launched straight from the command line:
Log Management
To consult logs just type the command:
Standard, Raw, JSON and formated output are available.
Examples:
To enable log rotation install the following module
More about log management
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
More about Startup Scripts Generation
Updating PM2
PM2 updates are seamless
PM2+ Monitoring
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!
CHANGELOG
CHANGELOG
Contributors
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.