pm2
PM2 is a production process manager for Node.js applications that provides process monitoring, automatic restarts, load balancing, log management, and zero-down…
Installation
npm install -g pm2
yarn add -g pm2
pnpm add -g pm2
Import
// Used as CLI: pm2 start app.js
Quick Example
// Start application:
// pm2 start app.js -i max --name my-app
// ecosystem.config.js
module.exports = {
apps: [{
name: 'api',
script: 'dist/server.js',
instances: 'max',
exec_mode: 'cluster',
env_production: { NODE_ENV: 'production' },
}],
};About pm2
PM2 is a production process manager for Node.js applications that provides process monitoring, automatic restarts, load balancing, log management, and zero-downtime deployments. PM2 runs Node.js applications as background daemons, automatically restarting them if they crash and providing real-time monitoring of CPU usage, memory consumption, request count, and uptime through both CLI output and a web-based dashboard. The cluster mode leverages Node.js's cluster module to spawn multiple application instances across all available CPU cores, with PM2 handling load balancing and worker management transparently. PM2 supports ecosystem files (ecosystem.config.js) for defining multiple application configurations with environment-specific settings, startup scripts that configure PM2 to launch applications on system boot, and a deployment system for pushing code to remote servers. The log management system handles log rotation, merges output from clustered instances, and supports structured JSON logging. PM2 integrates with monitoring services through PM2 Plus (formerly Keymetrics) for remote monitoring, alerting, and profiling. PM2 is the most widely used production process manager for Node.js, deployed across thousands of production servers worldwide.
Quick Facts
| Package | pm2 |
| Category | Utility |
| Weekly Downloads | 2M+ |
| License | AGPL-3.0 |
| Install | npm install -g pm2 |
Related Packages
Nodemon is a utility that monitors for file changes in your Node.js application and automatically re…
Express is the most widely used web application framework for Node.js, providing a minimal and flexi…
Fastify is a high-performance web framework for Node.js designed to be the fastest HTTP framework av…
Winston is the most popular logging library for Node.js, designed to be a simple and universal loggi…
Browse npm Packages by Category
Explore our reference of 200 popular npm packages with install commands, examples, and quick-start guides.