UNPKG

6.71 kBMarkdownView Raw
1<div align="center">
2 <br/>
3<picture>
4 <source
5 srcset="https://raw.githubusercontent.com/Unitech/pm2/master/pres/pm2-v4.png"
6 width=710px
7 media="(prefers-color-scheme: light)"
8 />
9 <source
10 srcset="https://raw.githubusercontent.com/Unitech/pm2/development/pres/pm2-v4-dark-mode.png"
11 width=710px
12 media="(prefers-color-scheme: dark), (prefers-color-scheme: no-preference)"
13 />
14 <img src="https://raw.githubusercontent.com/Unitech/pm2/master/pres/pm2-v4.png" />
15</picture>
16
17 <br/>
18<br/>
19<b>P</b>(rocess) <b>M</b>(anager) <b>2</b><br/>
20 <i>Runtime Edition</i>
21<br/><br/>
22
23
24<a title="Donate" href="https://explorer.kaspa.org/addresses/kaspa:qr2gxmun87mc8wt8adegy6fulvpfdjgsa8zcdxyulvzzr2utra3jv4s8txkq9">
25 <img src="https://img.shields.io/badge/donation-kaspa-green" alt="Donate"/>
26</a>
27
28<a title="PM2 Downloads" href="https://npm-stat.com/charts.html?package=pm2&from=2018-01-01&to=2023-08-01">
29 <img src="https://img.shields.io/npm/dm/pm2" alt="Downloads per Month"/>
30</a>
31
32<a title="PM2 Downloads" href="https://npm-stat.com/charts.html?package=pm2&from=2018-01-01&to=2023-08-01">
33 <img src="https://img.shields.io/npm/dy/pm2" alt="Downloads per Year"/>
34</a>
35
36<a href="https://badge.fury.io/js/pm2" title="NPM Version Badge">
37 <img src="https://badge.fury.io/js/pm2.svg" alt="npm version">
38</a>
39
40<br/>
41<br/>
42<br/>
43</div>
44
45
46PM2 is a production process manager for Node.js 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.
47
48Starting an application in production mode is as easy as:
49
50```bash
51$ pm2 start app.js
52```
53
54PM2 is constantly assailed by [more than 1800 tests](https://github.com/Unitech/pm2/actions/workflows/node.js.yml).
55
56Official website: [https://pm2.keymetrics.io/](https://pm2.keymetrics.io/)
57
58Works on Linux (stable) & macOS (stable) & Windows (stable). All Node.js versions are supported starting Node.js 12.X.
59
60
61### Installing PM2
62
63With NPM:
64
65```bash
66$ npm install pm2 -g
67```
68
69You can install Node.js easily with [NVM](https://github.com/nvm-sh/nvm#installing-and-updating) or [FNM](https://github.com/Schniz/fnm).
70
71### Start an application
72
73You can start any application (Node.js, Python, Ruby, binaries in $PATH...) like that:
74
75```bash
76$ pm2 start app.js
77```
78
79Your app is now daemonized, monitored and kept alive forever.
80
81### Managing Applications
82
83Once applications are started you can manage them easily:
84
85![Process listing](https://github.com/Unitech/pm2/raw/master/pres/pm2-ls-v2.png)
86
87To list all running applications:
88
89```bash
90$ pm2 list
91```
92
93Managing apps is straightforward:
94
95```bash
96$ pm2 stop <app_name|namespace|id|'all'|json_conf>
97$ pm2 restart <app_name|namespace|id|'all'|json_conf>
98$ pm2 delete <app_name|namespace|id|'all'|json_conf>
99```
100
101To have more details on a specific application:
102
103```bash
104$ pm2 describe <id|app_name>
105```
106
107To monitor logs, custom metrics, application information:
108
109```bash
110$ pm2 monit
111```
112
113[More about Process Management](https://pm2.keymetrics.io/docs/usage/process-management/)
114
115### Cluster Mode: Node.js Load Balancing & Zero Downtime Reload
116
117The 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).
118
119![Framework supported](https://raw.githubusercontent.com/Unitech/PM2/master/pres/cluster.png)
120
121Starting a Node.js application in cluster mode that will leverage all CPUs available:
122
123```bash
124$ pm2 start api.js -i <processes>
125```
126
127`<processes>` can be `'max'`, `-1` (all cpu minus 1) or a specified number of instances to start.
128
129**Zero Downtime Reload**
130
131Hot Reload allows to update an application without any downtime:
132
133```bash
134$ pm2 reload all
135```
136
137[More informations about how PM2 make clustering easy](https://pm2.keymetrics.io/docs/usage/cluster-mode/)
138
139### Container Support
140
141With the drop-in replacement command for `node`, called `pm2-runtime`, run your Node.js application in a hardened production environment.
142Using it is seamless:
143
144```
145RUN npm install pm2 -g
146CMD [ "pm2-runtime", "npm", "--", "start" ]
147```
148
149[Read More about the dedicated integration](https://pm2.keymetrics.io/docs/usage/docker-pm2-nodejs/)
150
151### Host monitoring speedbar
152
153PM2 allows to monitor your host/server vitals with a monitoring speedbar.
154
155To enable host monitoring:
156
157```bash
158$ pm2 set pm2:sysmonit true
159$ pm2 update
160```
161
162![Framework supported](https://raw.githubusercontent.com/Unitech/PM2/master/pres/vitals.png)
163
164### Terminal Based Monitoring
165
166![Monit](https://github.com/Unitech/pm2/raw/master/pres/pm2-monit.png)
167
168Monitor all processes launched straight from the command line:
169
170```bash
171$ pm2 monit
172```
173
174### Log Management
175
176To consult logs just type the command:
177
178```bash
179$ pm2 logs
180```
181
182Standard, Raw, JSON and formated output are available.
183
184Examples:
185
186```bash
187$ pm2 logs APP-NAME # Display APP-NAME logs
188$ pm2 logs --json # JSON output
189$ pm2 logs --format # Formated output
190
191$ pm2 flush # Flush all logs
192$ pm2 reloadLogs # Reload all logs
193```
194
195To enable log rotation install the following module
196
197```bash
198$ pm2 install pm2-logrotate
199```
200
201[More about log management](https://pm2.keymetrics.io/docs/usage/log-management/)
202
203### Startup Scripts Generation
204
205PM2 can generate and configure a Startup Script to keep PM2 and your processes alive at every server restart.
206
207Init Systems Supported: **systemd**, **upstart**, **launchd**, **rc.d**
208
209```bash
210# Generate Startup Script
211$ pm2 startup
212
213# Freeze your process list across server restart
214$ pm2 save
215
216# Remove Startup Script
217$ pm2 unstartup
218```
219
220[More about Startup Scripts Generation](https://pm2.keymetrics.io/docs/usage/startup/)
221
222### Updating PM2
223
224```bash
225# Install latest PM2 version
226$ npm install pm2@latest -g
227# Save process list, exit old PM2 & restore all processes
228$ pm2 update
229```
230
231*PM2 updates are seamless*
232
233## PM2+ Monitoring
234
235If you manage your apps with PM2, PM2+ makes it easy to monitor and manage apps across servers.
236
237![https://app.pm2.io/](https://pm2.io/img/app-overview.png)
238
239Feel free to try it:
240
241[Discover the monitoring dashboard for PM2](https://app.pm2.io/)
242
243Thanks in advance and we hope that you like PM2!
244
245## CHANGELOG
246
247[CHANGELOG](https://github.com/Unitech/PM2/blob/master/CHANGELOG.md)
248
249## Contributors
250
251[Contributors](http://pm2.keymetrics.io/hall-of-fame/)
252
253## License
254
255PM2 is made available under the terms of the GNU Affero General Public License 3.0 (AGPL 3.0).
256For other licenses [contact us](mailto:contact@keymetrics.io).