PM2Stack
A powerful library for managing PM2 processes with ease
Create, start, stop, and monitor multiple Node.js applications using PM2. Perfect for microservices, API gateways, and complex application stacks.
import { PM2Stack, PM2App } from 'pm2-stack';
const stack = new PM2Stack({ verbose: true });
const webApp = new PM2App({
id: 'web-server',
entryPoint: './app.js',
instances: 2,
env: { PORT: '3000' }
});
stack.registerApp(webApp);
await stack.start();
Features
Easy Process Management
Start, stop, and restart multiple PM2 processes with simple API calls.
TypeScript Support
Full TypeScript support with comprehensive type definitions and IntelliSense.
Cluster Mode
Support for both fork and cluster modes with configurable instance counts.
Environment Variables
Pass environment variables to your applications with ease.
Error Handling
Robust error handling with detailed error messages and stack traces.
Verbose Logging
Optional verbose logging for debugging and monitoring your applications.
Installation
npm install pm2-stack
yarn add pm2-stack
pnpm add pm2-stack
Prerequisites
- Node.js 16.0.0 or higher
- PM2 installed globally:
npm install -g pm2
Quick Start
Import the library
import { PM2Stack, PM2App } from 'pm2-stack';
Create a PM2Stack instance
const stack = new PM2Stack({
verbose: true,
exitOnStart: false
});
Create and register apps
const app = new PM2App({
id: 'my-app',
entryPoint: './app.js',
instances: 2,
env: { PORT: '3000' }
});
stack.registerApp(app);
Start the stack
await stack.start();
API Reference
Complete API documentation with detailed method descriptions, parameters, and examples.
View API DocumentationExamples
Practical code examples and use cases to help you get started quickly.
View Examples