Socket
Socket
Sign inDemoInstall

pm2

Package Overview
Dependencies
584
Maintainers
1
Versions
275
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    pm2

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


Version published
Maintainers
1
Install size
19.2 MB
Created

Package description

What is pm2?

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

What are pm2's main functionalities?

Process Management

Start an application with PM2 and keep it running in the background.

pm2 start app.js

Load Balancing

Enable load balancing by starting multiple instances of the application across all CPUs.

pm2 start app.js -i max

Monitoring

Monitor all processes launched with PM2 using a terminal-based dashboard.

pm2 monit

Logging

Display logs of all processes in real-time, or target specific processes.

pm2 logs

Startup Script

Generate a startup script to resurrect PM2 and all processes on server reboot.

pm2 startup

Update Processes

Reload all processes in the cluster without downtime.

pm2 reload all

Other packages similar to pm2

Changelog

Source

3.0.1 ( Mon Jul 23 2018 14:13:35 GMT+0200 (CEST) )

Bug Fixes

  • allow to set a name via pm2 link (ebffb609)
  • disable network monitoring as long as ampq not supported (ae1547bf)
  • display error message from pm2-deploy (9171b810)
  • protect geteuid/getegid from being called on windows #3793 (0495bd8e)
  • put message module at the right level (56f5e047)
  • do not ignore child pres folder (10ee9987)
  • let->var (89e2a125)
  • method renaming (f3faa3d8)
  • path (4f980550)
  • #3791 mitigate pidusage errores (88551b8c)
  • pm2 plus (9bc34e56)
  • #3764 (3a582b42)
  • drop coffee-script (installed via pm2 install coffeescript) (76ceb2fd)
  • restore no_interaction for pm2-dev (902e5a5a)
  • option -w doesn't work (165a05c8)
  • retab shell script to use space for indent consistency (e3b4327d)
  • set Makefile indent to tab instead of common space (4db0ae01)
  • set yaml file indent to 2 spaces instead of 3 (e4ecb0b2)
  • remove trailing spaces (5c115983)
  • fixes #3735 (0548cb82)

Hot Fixes

  • fix #3767, do not consider as a command if space and slash are found (d15a12ce)
  • fix #3767, do not consider as a command if space and slash are found (f8ec1503)

Features

  • add inspector for node 10 and heap snapshot (dc61bca6)
  • pm2 plus xx yy now generates a name with hostname-UID (fcf75e2c)
  • #3757 --only='app1,app2' (bea98330)
  • pm2 plus cli (1da6edde)
  • reload all apps after connection to pm2 plus (35a1ed2a)
  • ask to install module after connection with KM (68e87b39)
  • with pm2 plus command ask to install modules (28c61716)

Test

  • test with development packages (d361c840)

Chore

Branchs merged

  • Merge branch 'development' into uid-gen (5324c878)
  • Merge branch 'master' into development (7d04f638)

Pull requests merged

  • Merge pull request #3811 from Unitech/memory_inspector (62018044)
  • Merge pull request #3801 from vkotovv/grammar-fixes (9bb37a66)
  • Merge pull request #3799 from Unitech/refactor-agent (bcc4fea8)
  • Merge pull request #3787 from Unitech/multi-only (ea5d74a8)
  • Merge pull request #3788 from Unitech/uid-gen (f70444f3)
  • Merge pull request #3784 from Unitech/pm2-plus-cli (e8c13c37)
  • Merge pull request #3780 from Unitech/plus_modules (466d2701)
  • Merge pull request #3768 from Unitech/spaces (0477354b)
  • Merge pull request #3771 from chinesedfan/patch-2 (8de987a6)
  • Merge pull request #3762 from shaharmor/issue-3441 (429e455d)
  • Merge pull request #3761 from PeterDaveHello/fix-sh-indent-style (24cddc25)
  • Merge pull request #3737 from morugu/add-node-env-output (6628f163)
  • Merge pull request #3743 from vivex/master (06872c25)
  • Merge pull request #3748 from JimiC/support_nvm4win (2dac235b)
  • Merge pull request #3752 from PeterDaveHello/upstart.tpl (d4e66e3a)
  • Merge pull request #3753 from PeterDaveHello/fix-editorconfig (d1478680)
  • Merge pull request #3754 from PeterDaveHello/remove-trailing-space (b660f03e)

Readme

Source

PM2 is a Production Runtime and 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 facilitate common Devops 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.io/doc/

Works on Linux (stable) & macOS (stable) & Windows (stable). All Node.js versions are supported starting Node.js 4.X.

NPM

Installing PM2

$ npm install pm2 -g

npm is a builtin CLI when you install Node.js - Installing Node.js with NVM

Start an application

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

$ pm2 start app.js

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

More about Process Management

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

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|id|'all'|json_conf>
$ pm2 restart  <app_name|id|'all'|json_conf>
$ pm2 delete   <app_name|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 Application 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).

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

Seamlessly supported by all major Node.js frameworks and any Node.js applications without any code change:

Framework supported

More informations about how PM2 make clustering easy

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

More about log management

Startup Hooks Generation

PM2 can generates 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 Hooks

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

Ready to Scale? Go further with PM2 Plus!



PM2 plus logo

PM2
Plus Edition

$ pm2 plus

Once you scale you need to make sure that your application is running properly, without bugs, performance issues and without downtimes.

That's why we created PM2 Plus. It's a set of advanced features for both hardening the PM2 Runtime and monitoring applications in production.

With PM2 Plus you get:

  • A Real-time Monitoring Web Interface
  • Smart Exception Reporting
  • Production Profiling for Memory and CPU
  • PM2 Runtime High Availability Fallback

And much more like realtime logs, custom metrics, remote actions...

You can also create account via the app: here

PM2 Plus Features

Visual Memory Snapshots:

https://raw.githubusercontent.com/Unitech/pm2/master/pres/memory-profiling.png

CPU FlameGraphs:

https://raw.githubusercontent.com/Unitech/pm2/master/pres/flamegraph.png

Multi Server Overview:

https://raw.githubusercontent.com/Unitech/pm2/master/pres/pm2-ls-multi.png

PM2 Plus: Expose Custom Metrics

To get more insights on how your application behave, plug custom metrics inside your code and monitor them with the pm2 monit command:

In your project install pm2-io-pm:

$ npm install @pm2/io --save

Then plug a custom metric:

const io = require('@pm2/io');

let counter = 1;

const latency = io.metric({
   name    : 'Counter',
   value   : function() {
     return counter;
   }
});

setInterval(() => {
  counter++;
}, 1000);

PM2 Plus: Module system

PM2 embeds a simple and powerful module system. Installing a module is straightforward:

$ pm2 install <module_name>

Here are some PM2 compatible modules (standalone Node.js applications managed by PM2):

pm2-logrotate automatically rotate logs and limit logs size
pm2-server-monit monitor the current server with more than 20+ metrics and 8 actions

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.

GA

Keywords

FAQs

Last updated on 24 Jul 2018

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc