What's up with PM2.X?
by Shubham SHARMA -


Here are some statistics recap of PM2:

  • Iterations days: 1355 days (˜3.7 years)
  • Total Downloads: 21 million
  • Current Version: 2.4.1

So what's new with PM2 since 2.X?
A lot.

Let's highlight some nifty features you may have missed.

pm2 expose [path]

This new command allows you to easily expose a folder (that must include an index.html) over the internet. Behind the scene, it starts a simple Node.js server and expose the file in the target folder. Make sure to at least place a "index.html" at the root of this folder.

$ pm2 expose my_static_website/ --port 3030
$ google-chrome localhost:3030

pm2 monit

We included the awesome blessed library into PM2 to be able to build a termcap dashboard. Now by typing pm2 monit or pm2 dashboard you are now able to get a bird eye view of every Node.js applications managed by PM2, from logs, CPU, memory, custom metrics to metadatas.

pm2 monit

$ pm2 monit

Note you can still access to the legacy pm2 monit interface by typing pm2 imonit.

Docker integration

Thanks to Simone Primasora and PM2 contributors we now have a great integration with Docker.

The pm2-docker integration has got a lot of enhancements and the official Docker image pm2-docker-alpine is now widely used.

pm2-docker builtin command (when installing pm2):

$ pm2-docker ecosystem.config.js

Launching the pm2-docker-alpine container:

$ docker pull keymetrics/pm2-docker-alpine
$ docker run -p 80:3000 -v `pwd`/example_app:/app keymetrics/pm2-docker-alpine

Responsive CLI

Yes, responsiveness is not only for browser and mobiles. Terminal interfaces also needs responsive adjustments!

responsive list

$ pm2 ls

Multi platform, users system

We've refactored the startup script generation system and we now support every init system:

  • systemd
  • systemv
  • openrc
  • upstart
  • launchd

Thanks to Rasmus Porsager we even support multi user script generation!

$ pm2 startup [systemd|systemv|openrc|upstart|launchd]
$ pm2 unstartup

apt install pm2

For each release we now publish a .deb package to allow installation via apt (Advanced Package Tool):

sudo apt-key adv --keyserver keyserver.ubuntu.com --recv D1EA2D4C  
echo "deb http://apt.pm2.io/ubuntu stable main" | sudo tee /etc/apt/sources.list.d/pm2.list  
sudo apt update  
sudo apt install pm2  

Make sure you already have Node.js installed

Node.js version configuration

You're using NVM right? So by using the Process Configuration File (sometime called ecosystem) you can now specify the Node.js version you want your application to be run with by setting the interpreter to the desired Node.js version.

module.exports = {  
  apps : [{
    name  : 'API',
    script: './api.js',
    interpreter : 'node@7.5.0' 


$ pm2 start ecosystem.config.js

Advanced Interactions with PMX

PMX is not only for Keymetrics. Sure, Keymetrics can augment and harden your Node.js application. But every real-time features, like displaying custom metrics or triggering custom functions can be done directly within PM2.

Expose Metrics

var Probe = require('pmx').probe();

  name    : 'Realtime user',
  value   : function() {
    return Object.keys(users).length;

Then start your application that use this probes and open pm2 monit to view this metric.

Expose Functions

var pmx = require('pmx');

pmx.action('db:clean', function(reply) {  
  clean.db(function() {
     reply({success : true});

Then do pm2 show to display available actions and do:

$ pm2 trigger <app_name> <function_name>

Final words

This are the new key features landed in PM2 2.x but there are also hundreds of issues fixed.

We LOVE ideas and suggestions, so please feel confident about posting your thoughts and ideas on the PM2 issue system.

We are almost 300 on the pm2 slack to discuss about the future of pm2. Make sure to join us on http://slack.pm2.io

Node.js is getting bigger, faster and with PM2 we are really proud to help developers, hackers and enterprises get the most of their Node.js applications.

Future is bright for Node.js!