Nodejs application monitoring is very important in the production environment. Because There is a lot of critical part in Nodejs application like memory usage, memory leak, deployment process, etc. In this article, you will learn How to properly monitor your Nodejs application using PM2.

What is PM2

PM2 is a process manager for Nodejs application and It is simple and easy to use. PM2 is providing an easy way to manage and daemonize(runs as a background process) Nodejs applications. It will help us for reloading application in case of any exception.


PM2 supports for NodeJS based web application framework like Express, Hapi, Geddy and Sail etc.

Key features:

  • PM2 manages all process (start/stop/restart/delete/show/monit)
  • Built-in load balancer
  • Process Monitoring
  • Max memory reload without downtime
  • Keep your applications alive forever
  • Easy log management for processes
  • View performance metrics on your application
  • Development, Deployment workflow
  • Startup Scripts
  • Keymetrics monitoring on web platform


Using node package manager(npm), you can install PM2 on the server.

npm install pm2 -g

This package should be installed as a global node.



PM2 is having the simplest command to start, daemonize and monitor your application.

pm2 start helloworld.js You can set the name for your process using below command. pm2 start helloworld.js –name MyWorld



Using below command, you can display all the processes with status.

pm2 list


To stop an application, you can use below command.

pm2 stop <id|name>

//Stop all processes

pm2 stop all


Restart the previous app launched by name

pm2 restart <id|name>

pm2 restart all


stop and delete a process from pm2 process list

pm2 delete <id|name> pm2 delete all


To get more details about an application

pm2 show <id|name>


To monitor the resource usage of your application

pm2 monit pm2 monit <id|name>



To stop the PM2

pm2 kill


Your application logs are stored into server hard disk.

pm2 logs

PM2 with Keymetrics:

Keymetrics is a web platform for monitoring and managing your application using PM2. There are lot of features in keymetrics like Memory Monitoring, exception reporting, load balancer, process control and more. Just you have run your application using PM2 and Keymetrics will give more details about your application.


Sample Script:


var http = require(“http”);

http.createServer(function (request, response) {

response.writeHead(200, {‘Content-Type’: ‘text/html’});

response.end(‘<h1>PM2 Hello World</h1>\n’);


console.log(‘Server running at’);

C:\pm2 start pm2world.js

[PM2] Starting C:\pm2world.js in fork_mode (1 instance)

[PM2] Done.

pm2 output