LLMpediaThe first transparent, open encyclopedia generated by LLMs

pm2 (process manager)

Generated by GPT-5-mini
Note: This article was automatically generated by a large language model (LLM) from purely parametric knowledge (no retrieval). It may contain inaccuracies or hallucinations. This encyclopedia is part of a research project currently under review.
Article Genealogy
Parent: net (Node.js) Hop 4
Expansion Funnel Raw 39 → Dedup 0 → NER 0 → Enqueued 0
1. Extracted39
2. After dedup0 (None)
3. After NER0 ()
4. Enqueued0 ()
pm2 (process manager)
Namepm2
DeveloperKeymetrics
Initial release2013
Programming languageJavaScript
Operating systemCross-platform
LicenseGNU GPLv3

pm2 (process manager) is a production process manager for Node.js applications that provides process monitoring, clustering, and automated restarts. It is widely used by developers and operations teams for managing long-running JavaScript services, integration with continuous delivery pipelines, and centralized process supervision. Early adopters included startups and enterprises leveraging Node.js for web servers, microservices, and background workers.

Overview

pm2 was created to address reliability and scalability for Node.js deployments while integrating with tools from the DevOps and cloud ecosystems. It competes with and complements projects from the same era like forever (software), Upstart, systemd, Supervisor (process-control system), and runit, offering features tailored to JavaScript runtime patterns and the V8 (JavaScript engine) execution model. Keymetrics, the company behind pm2, emphasized metrics, process state, and cluster management as differentiators versus general init systems and platform services such as Heroku and AWS Elastic Beanstalk.

Features

pm2 provides ecosystem features including process lifecycle management, zero-downtime reloads, log aggregation, and metrics collection. It supports cluster mode leveraging Node.js cluster APIs for multi-core utilization, process file descriptors inheritance for graceful restarts, and process-level environment variable management for staging and production workflows. Integration points and extensions include monitoring dashboards, event hooks compatible with GitHub Actions, Jenkins, Travis CI, and container orchestration systems like Docker and Kubernetes.

Installation and configuration

pm2 is distributed via the npm package registry and typically installed globally on servers. System boot integration is supported through generated init scripts compatible with systemd, Upstart, and legacy SysVinit, enabling pm2 to resurrect processes after host reboots. Configuration commonly uses ecosystem files in JSON or YAML formats which declare applications, environment sections, and interpreter options; these files are often stored alongside source in repositories managed with Git and deployed by CI/CD tools like CircleCI or GitLab CI/CD.

Usage and commands

Common pm2 workflows include starting, stopping, reloading, and listing processes via a CLI designed for operators and automation. Typical commands interact with process ids and names, and can be integrated into deployment scripts invoked by Ansible, Chef, or Puppet. The CLI exposes subcommands for scaling in cluster mode, generating process dumps for diagnostic analysis, and exporting process lists for boot-time restoration. Operators often combine pm2 command sequences with monitoring services such as New Relic and Datadog to trigger alerts and automated remediation.

Architecture and internals

Internally pm2 implements a master-worker model where a daemon orchestrates child processes and maintains state about restarts, uptime, and resource usage. In cluster mode it uses the Node.js cluster mechanism and the libuv event loop to distribute incoming connections across worker processes. The pm2 daemon persists state to local files and can interface with external backends for metrics; it also manages IPC channels for actions like graceful reload or application-level messaging. The project architecture aligns with patterns used by process supervisors such as Supervisor (process-control system) and runit while optimizing for the semantics of the V8 engine and Node.js module resolution.

Monitoring, logging, and clustering

pm2 centralizes stdout and stderr streams into structured logs and supports log rotation to manage disk consumption, often coordinated with log aggregation platforms like ELK Stack, Splunk, or Graylog. The Keymetrics dashboard (commercial offering) provides visualizations of CPU, memory, and event rates and integrates with alerting systems such as PagerDuty and Opsgenie. For horizontal scaling, pm2’s cluster mode enables spawning multiple workers per host to utilize multiple CPU cores, complementing container-level orchestration performed by Docker Swarm or Kubernetes, and supporting blue-green or rolling update strategies used in deployments by organizations like Netflix and Airbnb.

Security and best practices

Secure deployment of pm2 involves running processes under least-privilege service accounts, isolating applications with container runtimes from vendors like Docker, and avoiding use of root for runtime execution. Best practices include pinning module and runtime versions via Semantic Versioning conventions, auditing dependencies with tools inspired by OWASP guidance, and tying pm2 lifecycle actions into formal CI/CD pipelines to ensure reproducibility. For environments requiring compliance, operators combine pm2 process controls with host-level security frameworks such as SELinux or AppArmor and centralized secret management solutions like HashiCorp Vault.

Category:Node.js