How to use PM2

Updated on Mar 13, 2019

Pm2 is a process management module for Node.js applications. It is used to start and monitor Node.js application so if the application goes down ( for example if the node index.js process dies) the process manager will restart the app immediately making it available once again. In case you are using our NodeJS selector you won’t need pm2 to keep your apps up and running, but if you are one of our users that prefer their own setup, pm2 will prove useful to you.

To start your application with pm2 you will need to input the following command via the console:
 

pm2 start app.js

 

Starting a nodejs app with pm2
 

You will be presented with a table containing all the applications you have added to Pm2. In our case, since this is our first app, the table only has one entry. Please note that using that command will give an automatic name to the application which you will have to then use as a reference when executing pm2 commands against the application. For example, to stop the Pm2 monitoring over the app.js application get the name of the application using:
 

pm2 ls

 

This will bring the table with all the applications again. Find the server application which should be currently online if you have followed the previous actions of this tutorial. Then to stop it just run:
 

pm2 stop app

 

Stopping a nodejs application via pm2

 

The application will then be listed as stopped.

You may have noticed that in the last screenshot we have an additional line stating a dashboard link and server info. This is a feature of Keymetrics – a dashboard solution from the creator of PM2.

 

Keymetrcs dashboard overview

Image source: https://blog.pm2.io/from-keymetrics-to-pm2-plus

 

The idea is to provide the user with as much information in real time as possible regarding his application and its usage of resources.

You can create a Keymetrics.io account without even leaving the terminal. Simply type:
 

pm2 monitor

 

Now you will have to create a username and provide an email for your newly registered account. Once done, you will be presented with a link to your dashboard.

 

pm2 monitoring activation via keymetrics

 

If you have already started an app via pm2 it will also be displayed there.

 

Monitoring nodejs projects via Keymetrics

 

The PM2 team is already building on top of the Keymetrics platform and has created PM2+.

 

Image source: https://blog.pm2.io/from-keymetrics-to-pm2-plus

 

This new system seems to have a complete overhaul of the metrics it can provide as well as their visual representation.

 

Image source: https://blog.pm2.io/from-keymetrics-to-pm2-plus

 

While most of the features included in it are paid, you can still check your app’s status even with your Keymetrics credentials.

 

With all of this you should have a solid monitoring solution configured for your application. Whether its our NodeJS selector via which you can monitor, restart and stop your app or PM2's functionality or externdal dashboard, your project will surely stay up for as long as you want it to.

On this page...

    Node.js Hosting

    • Multiple Node Versions
    • 24/7 Node.js Support
    • Free Domain for life
    • Hack-free Protection
    • Fast SSD Storage
    • Free Node.js Transfer
    • Free CloudFlare CDN
    • Immediate Activation
    View More