MCPcopy
hub / github.com/Unitech/pm2

github.com/Unitech/pm2 @v7.0.3 sqlite

repository ↗ · DeepWiki ↗ · release v7.0.3 ↗
1,321 symbols 4,762 edges 592 files 214 documented · 16%
README

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 a comprehensive test suite.

Official website: https://pm2.keymetrics.io/

Works on Linux, macOS, and Windows. Supports Node.js 18+ and Bun 1+.

Installing PM2

With NPM

$ npm install pm2 -g

With Bun

$ bun install pm2 -g

If you only have Bun installed (no Node.js), symlink node to bun so PM2's #!/usr/bin/env node shebang resolves to Bun's node-compatibility runtime:

$ sudo ln -s $(which bun) /usr/local/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

Cluster mode starts multiple Node.js processes and load-balances HTTP/TCP/UDP queries between them. This significantly increases throughput on multi-core machines and improves 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 information about how PM2 makes 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 formatted 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, systemv, openrc, launchd, rcd, rcd-openbsd, smf

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

Extension points exported contracts — how you extend this code

Error (Interface)
* * * Node.js v6.x API * * [1 implementers]
examples/using-pm2-and-transpilers/node.d.ts
Pm2Env (Interface)
* The list of path variables in the process’s environment
types/index.d.ts
NodeBuffer (Interface)
* @deprecated
examples/using-pm2-and-transpilers/node.d.ts
Proc (Interface)
(no doc)
types/index.d.ts
FSWatcher (Interface)
(no doc) [1 implementers]
examples/using-pm2-and-transpilers/node.d.ts
Command (Interface)
(no doc)
types/index.d.ts
WriteStream (Interface)
(no doc) [1 implementers]
examples/using-pm2-and-transpilers/node.d.ts
ProcessDescription (Interface)
(no doc)
types/index.d.ts

Core symbols most depended-on inside this repo

cb
called by 807
modules/pm2-io-agent/test/units/transporters/WebsocketTransport.mocha.js
done
called by 635
modules/pm2-axon/test/test.emitter.many.js
on
called by 441
examples/using-pm2-and-transpilers/node.d.ts
exitCli
called by 211
lib/API.js
send
called by 187
examples/using-pm2-and-transpilers/node.d.ts
toString
called by 178
examples/using-pm2-and-transpilers/node.d.ts
indexOf
called by 163
examples/using-pm2-and-transpilers/node.d.ts
close
called by 159
examples/using-pm2-and-transpilers/node.d.ts

Shape

Method 643
Function 387
Class 170
Interface 121

Languages

TypeScript100%
Python1%

Modules by API surface

examples/using-pm2-and-transpilers/node.d.ts335 symbols
lib/API.js45 symbols
modules/pm2-io-agent/src/Utility.js29 symbols
lib/tools/json5.js23 symbols
modules/pm2-io-bpm/pmx.js21 symbols
modules/pm2-io-agent/src/push/TransactionAggregator.js20 symbols
modules/pm2-io-bpm/utils/metrics/histogram.js19 symbols
modules/pm2-io-bpm/utils/transactionAggregator.js17 symbols
lib/tools/SysMetrics.js17 symbols
modules/pm2-io-bpm/profilers/inspectorProfiler.js16 symbols
lib/API/pm2-plus/auth-strategies/CliAuth.js16 symbols
modules/pm2-io-bpm/utils/BinaryHeap.js15 symbols

Dependencies from manifests, versioned

@pm2/blessed0.1.81 · 1×
@pm2/js-api0.8.1 · 1×
@pm2/pm2-version-check1.0.4 · 1×
amp0.3.1 · 1×
amp-message0.1.2 · 1×
ansis4.0.0-node10 · 1×
async3.2.6 · 1×
chokidar3.6.0 · 1×
cli-tableau2.0.1 · 1×
commander2.15.1 · 1×
croner4.1.97 · 1×
dayjs1.11.15 · 1×

Datastores touched

dbDatabase · 1 repos

For agents

$ claude mcp add pm2 \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact