UNPKG

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