⚠️ Development Notice: This project is currently under active development and is not production ready. Use with caution and expect breaking changes.

API Reference

Complete documentation for PM2Stack classes and methods

Detailed API documentation for all PM2Stack classes, methods, and configuration options.

PM2Stack

The main class for managing PM2 processes. Create an instance to register and manage multiple applications.

Constructor

new PM2Stack(options?: PM2StackOptions)

Options

  • verbose?: boolean - Enable verbose logging (default: false)
  • exitOnStart?: boolean - Exit process after starting (default: true)

Methods

registerApp(app: PM2App): void

Register a PM2App with the stack. Must be called before starting the stack.

Parameters
  • app - The PM2App instance to register

start(): Promise<void>

Start all registered applications using PM2. This method will:

  • Connect to PM2 daemon
  • Start all registered applications
  • Remove any running apps not in the current stack
  • Optionally exit the process if exitOnStart is true

stop(): Promise<void>

Stop all registered applications and disconnect from PM2. This method will:

  • Stop all registered applications
  • Disconnect from PM2 daemon
  • Exit the process

isStarted(): boolean

Check if the stack has been started.

Returns

boolean - True if the stack has been started, false otherwise

PM2App

Represents a single application to be managed by PM2. Each app has its own configuration including entry point, instances, and environment variables.

Constructor

new PM2App(config: PM2AppConfig)

Configuration

  • id: string - Unique identifier for the app
  • entryPoint: string - Path to the application entry point
  • instances?: number - Number of instances (default: 1)
  • env?: object - Environment variables

Methods

getConfig(): PM2AppConfig

Get the current configuration of the app.

Returns

PM2AppConfig - The app configuration object

getPM2Config(): pm2.StartOptions

Get the PM2 configuration object for starting the app. This converts the PM2App configuration to PM2's expected format.

Returns

pm2.StartOptions - PM2 start options object

Types

PM2StackOptions

type PM2StackOptions = {
  verbose?: boolean;
  exitOnStart?: boolean;
}

PM2AppConfig

type PM2AppConfig = {
  id: string;
  entryPoint: string;
  cluster?: boolean;
  instances?: number;
  env?: { [key: string]: string };
}