What is PM2 and How Can You Use It?

November 6, 2025 / Tutorial

In this article, you will learn what PM2 is and how it can be used to manage and monitor Node.js applications in a production environment. It covers installation, key features, and essential commands to help you keep your apps running smoothly.

What is PM2?

PM2 (Process Manager 2) is a production process manager for Node.js applications. It helps developers manage, monitor, and keep applications running continuously without manual intervention. PM2 automatically restarts apps if they crash, supports load balancing across CPU cores, and provides tools for performance monitoring and log management.

Features

  • Automatic Restarts: Automatically restarts applications after a crash or error.
  • Cluster Mode: Distributes workload across multiple CPU cores for better performance.
  • Monitoring: Tracks CPU and memory usage in real time.
  • Logging: Provides combined and error log management.
  • Startup Scripts: Enables apps to start automatically when the system reboots.
  • Zero-Downtime Reloads: Allows updates or restarts without service interruption.
  • Configuration Files: Supports JSON/YAML configuration files for multiple applications.

Installation

  1. Install PM2 globally using npm:
    npm install -g pm2
  2. Check the installation using the following command:
    pm2 --version

Basic Commands

  1. pm2 start app.js – Starts an application.
  2. pm2 list – Lists all running applications.
  3. pm2 stop <app_name> – Stops a running application.
  4. pm2 restart <app_name> – Restarts the specified app.
  5. pm2 delete <app_name> – Removes an application from PM2’s process list.
  6. pm2 logs <app_name> – Displays logs for a specific application.
  7. pm2 monit – Opens the PM2 monitoring dashboard.

Using Cluster Mode

Cluster mode allows PM2 to run multiple instances of an application across CPU cores.

Example:

pm2 start app.js -i max

The -i max flag automatically launches one instance per available CPU core.

Auto-Start on Boot

To make PM2-managed applications start automatically after a reboot, use:

pm2 startup
pm2 save

pm2 startup generates a startup script, and pm2 save saves the current list of running applications.

Monitoring and Logs

You can view and monitor applications directly from the command line:

pm2 logs
pm2 monit

For advanced monitoring, PM2 can be connected to PM2 Plus, which provides a web-based dashboard.

This way, we can conclude that PM2 is a powerful and easy-to-use process manager for Node.js applications. It helps ensure uptime, simplifies scaling with cluster mode, and provides useful monitoring tools for production environments.