⚡ This is the AMP version of this page. View full version

PM2

Published: 7/7/2025 | Updated: 6/7/2025

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.

Installation

Install PM2 globally using npm:

npm install pm2 -g

Basic Commands

Starting an Application

To start an application:

pm2 start api.js

You can also start an application from an npm script:

# Example: pm2 start "npm run start"

To start an application with arguments

pm2 start api.js -- arg1 arg2

Managing Processes

Log Management

Display logs for a specific application:

pm2 logs <app_name>

Startup Script

Generate a startup script to automatically restart PM2 and your processes on server reboot:

pm2 startup

After running startup, you need to save the current process list:

pm2 save