Generated by GPT-5-mini| PM2 (software) | |
|---|---|
| Name | PM2 |
| Developer | Keymetrics |
| Initial release | 2013 |
| Latest release | 5.x |
| Written in | JavaScript |
| Operating system | Cross-platform |
| License | AGPL |
| Website | Keymetrics |
PM2 (software) is a production process manager for Node.js applications designed to simplify application deployment, process supervision, and monitoring across development and production environments. It provides process lifecycle management, clustering, logging, metrics, and integration with deployment tools and cloud platforms to support scalable services and microservices architectures.
PM2 was created to manage Node.js processes with features for process restarting, clustering, and log aggregation. It targets deployments used by teams working with Node.js, Linux, macOS, Windows, and container platforms such as Docker. The project was developed by the company Keymetrics and has been adopted by organizations using Amazon Web Services, Microsoft Azure, Google Cloud Platform, and private datacenters. PM2 often complements orchestration tools like Kubernetes and configuration management systems such as Ansible, Chef, and Puppet.
PM2 offers process management capabilities including zero-downtime reloads, automatic restarts, and process clustering using the Node.js Cluster module, enabling exploitation of multi-core x86 and ARM servers. It provides built-in log management with features comparable to ELK Stack integrations, supports runtime metrics collection similar to Prometheus exporters, and has process monitoring dashboards inspired by solutions like Datadog and New Relic. PM2 includes an ecosystem of modules and hooks that connect to GitLab CI/CD, Jenkins, Travis CI, and CircleCI pipelines for continuous deployment. For stateful applications, it interacts with storage systems such as Redis and message brokers including RabbitMQ and Apache Kafka.
PM2's architecture centers on a managing daemon supervising worker processes. The daemon interacts with the Node.js Cluster module to spawn worker processes and coordinates inter-process communication through IPC channels. Core components include the PM2 daemon, CLI client, and optional Keymetrics dashboard agent. PM2 stores runtime metadata and process state which can be integrated with external process supervisors like systemd, upstart, and supervisord. The tool's extensibility allows modules to interface with observability platforms such as Grafana, InfluxDB, and StatsD.
Developers use the PM2 CLI to start, stop, and manage applications with commands that can export process lists to startup scripts for systemd or init.d integration. Typical commands include starting applications in fork or cluster mode, reloading applications for zero-downtime deployments, and generating ecosystem configuration files (ecosystem.config.js) for multi-application orchestration. PM2 integrates with CI/CD workflows in GitHub Actions and supports process metrics retrieval for ingestion into OpenTelemetry pipelines. Administrators employ PM2 to manage process restarts on failure and to orchestrate graceful shutdowns during maintenance windows.
PM2 is used in deployment patterns ranging from single-server services to distributed microservices architectures deployed on Docker Swarm and Kubernetes. It works with container registries and image build pipelines in Docker Hub and Google Container Registry and can be embedded in base images alongside Nginx or HAProxy reverse proxies. Integration with configuration stores like Consul and etcd enables service discovery while deployment automation with Terraform and Pulumi orchestrates infrastructure provisioning. PM2's ability to generate startup scripts aids compatibility with cloud-init and instance provisioning workflows used by Amazon EC2 and Google Compute Engine.
PM2 provides runtime metrics on CPU and memory consumption per process, facilitating performance tuning for high-throughput services such as web servers built with Express.js or APIs using Fastify. Its logging subsystem centralizes stdout and stderr streams, rotating logs and enabling forwarding to logging backends like Fluentd or Logstash. For advanced monitoring, PM2 integrates with observability tools such as Prometheus and Grafana for dashboarding and alerting, and with APM solutions like New Relic and Datadog for transaction tracing. Load testing coordinated with tools like Apache JMeter and wrk helps evaluate PM2-managed clusters under realistic workloads.
When using PM2 in production, follow best practices including running processes under dedicated service accounts managed by OpenBSD-style privilege separation, employing TLS termination via Let's Encrypt certificates at reverse proxies like Nginx, and enforcing network controls with iptables or cloud security groups from AWS Identity and Access Management. Secure configuration involves minimal privileges for startup scripts integrated with systemd unit files, using immutable container images, and scanning packages against advisories from NPM Advisory and Snyk. For secrets management, integrate PM2 deployments with HashiCorp Vault or cloud secret stores provided by AWS Secrets Manager and Google Secret Manager to avoid embedding credentials in ecosystem files.
Category:Process management software