Skip to content

Package manager by kuldeep

December 21, 2022 | 12:00 AM

PM2

PM2 is a powerful process manager for Node.js applications. It allows you to keep applications alive forever, reload them without downtime, facilitate common system admin tasks, and much more. Here’s a comprehensive list of PM2 commands and their descriptions:

Ecosystem file

module.exports = {
  apps: [
    {
      name: "example1",
      script: "serve",
      instances: 1,
      autorestart: true,
      watch: false,
      max_memory_restart: "300M",
      env: {
        PM2_SERVE_PATH: "example1/dist",
        PM2_SERVE_PORT: "3001",
        PM2_SERVE_SPA: "true",
      },
    },
    {
      name: "example2",
      script: "serve",
      instances: 1,
      autorestart: true,
      watch: false,
      max_memory_restart: "300M",
      env: {
        PM2_SERVE_PATH: "example2/dist",
        PM2_SERVE_PORT: "3002",
        PM2_SERVE_SPA: "true",
      },
    },
  ],
}

Starting, Stopping, and Restarting Applications

Managing Application Logs

Monitoring and Management

Cluster Mode

Ecosystem File

Keymetrics Integration

Advanced Commands

These commands cover a wide range of functionalities provided by PM2, from basic process management to advanced features like cluster mode, ecosystem file management, and integration with Keymetrics for monitoring and management.

How to

React app

pm2 serve build 3000 --spa

Nextjs app

pm2 start --name website_name npm -- start

Nextjs app with 3 instance

pm2 start --name website_name -i 3 npm -- start