@arcblock/pm2

中文文档
6.0.12发布于 2025/07/28AGPL-3.0TypeScriptCommonJS近 30 天下载 2982

Production process manager for Node.JS applications with a built-in load balancer.

原始使用文档
文档目录16 节
  1. Installing PM2
  2. With NPM
  3. With Bun
  4. Start an application
  5. Managing Applications
  6. Cluster Mode: Node.js Load Balancing & Zero Downtime Reload
  7. Container Support
  8. Host monitoring speedbar
  9. Terminal Based Monitoring
  10. Log Management
  11. Startup Scripts Generation
  12. Updating PM2
  13. PM2+ Monitoring
  14. CHANGELOG
  15. Contributors
  16. License

https://raw.githubusercontent.com/Unitech/pm2/master/pres/pm2-logo-2.png

P(rocess) M(anager) 2
Runtime Edition

Downloads per Month Downloads per Year npm version


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 start app.js

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

$ npm install pm2 -g

With Bun

$ bun install pm2 -g

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/node


You can install Node.js easily with NVM or FNM or install Bun with curl -fsSL https://bun.sh/install | bash

Start an application

You can start any application (Node.js, Bun, and also Python, Ruby, binaries in $PATH...) like that:

$ pm2 start app.js

Your app is now daemonized, monitored and kept alive forever.

Managing Applications

Once applications are started you can manage them easily:

Process listing

To list all running applications:

$ pm2 list

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>

To have more details on a specific application:

$ pm2 describe <id|app_name>

To monitor logs, custom metrics, application information:

$ pm2 monit

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

Framework supported

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:

$ pm2 reload all

More informations about how PM2 make clustering easy

Container Support

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:

RUN npm install pm2 -g
CMD [ "pm2-runtime", "npm", "--", "start" ]

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:

$ pm2 set pm2:sysmonit true
$ pm2 update

Framework supported

Terminal Based Monitoring

Monit

Monitor all processes launched straight from the command line:

$ pm2 monit

Log Management

To consult logs just type the command:

$ pm2 logs

Standard, Raw, JSON and formated output are available.

Examples:

$ pm2 logs APP-NAME       # Display APP-NAME logs
$ pm2 logs --json         # JSON output
$ pm2 logs --format       # Formated output

$ pm2 flush               # Flush all logs
$ pm2 reloadLogs          # Reload all logs

To enable log rotation install the following module

$ pm2 install pm2-logrotate

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

# Generate Startup Script
$ pm2 startup

# Freeze your process list across server restart
$ pm2 save

# Remove Startup Script
$ pm2 unstartup

More about Startup Scripts Generation

Updating PM2

# Install latest PM2 version
$ npm install pm2@latest -g
# Save process list, exit old PM2 & restore all processes
$ pm2 update

PM2 updates are seamless

PM2+ Monitoring

If you manage your apps with PM2, PM2+ makes it easy to monitor and manage apps across servers.

https://app.pm2.io/

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.

版本与发布记录

@arcblock/pm2 共发布 13 个版本,首次发布于 2024/06/17;过去 12 个月发布了 0 个版本。

版本发布日期距今
6.0.12latest2025/07/281.3 年前
6.0.12-beta-2025-07-28-16-21-536beta2025/07/281.3 年前
6.0.112025/07/241.3 年前
6.0.11-beta-2025-07-24-08-55-9082025/07/241.3 年前
6.0.102025/07/231.3 年前
6.0.10-beta-2025-07-23-09-04-5312025/07/231.3 年前

关于 @arcblock/pm2 的常见问题

@arcblock/pm2 是什么?

Production process manager for Node.JS applications with a built-in load balancer.

如何安装 @arcblock/pm2?

在项目目录运行 npm install @arcblock/pm2,或使用 pnpm add / yarn add / bun add。它还提供命令行工具 pm2、pm2-dev、pm2-docker、pm2-runtime,可以用 npx pm2 直接运行。

@arcblock/pm2 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@arcblock/pm2 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@arcblock/pm2 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=16.0.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@arcblock/pm2 可以商用吗?

@arcblock/pm2 使用 AGPL-3.0 许可。最严格的 Copyleft:除分发外,通过网络向用户提供基于它的服务也需要开源对应源码。闭源 SaaS 使用前务必评估。以上为概括,不构成法律意见,请以许可原文为准。

@arcblock/pm2 的下载量有多少?

根据 npm 官方下载统计,@arcblock/pm2 在 2026/10/07 – 2026/11/05 这 30 天内被下载 2,982 次,日均约 99 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@arcblock/pm2 还在维护吗?

最新版本 6.0.12 发布于 2025/07/28(1.3 年前);至今共发布 13 个版本,其中过去 12 个月发布了 0 个;首次发布于 2024/06/17。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。