Production process manager for Node.JS applications with a built-in load balancer.
—
Quality
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Complete TypeScript interface and type definitions for PM2, providing full type safety for programmatic usage. All interfaces match the actual PM2 implementation and provide comprehensive type coverage for process management, configuration, and monitoring operations.
Comprehensive configuration options for starting PM2 processes.
interface StartOptions {
/** Process name for PM2 identification */
name?: string;
/** Script file path to execute */
script?: string;
/** Arguments passed to the script */
args?: string | string[];
/** Arguments passed to the interpreter */
interpreter_args?: string | string[];
/** Working directory for the process */
cwd?: string;
/** Environment variables */
env?: { [key: string]: string };
/** Number of instances for cluster mode */
instances?: number;
/** Execution mode: 'fork' or 'cluster' */
exec_mode?: string;
/** Enable file watching for auto-restart */
watch?: boolean | string[];
/** Patterns to ignore when watching files */
ignore_watch?: string[];
/** Merge cluster instance logs into single files */
merge_logs?: boolean;
/** Custom stdout log file path */
output?: string;
/** Custom stderr log file path */
error?: string;
/** Log timestamp format (moment.js format) */
log_date_format?: string;
/** Custom PID file path */
pid?: string;
/** Enable auto restart on crash (default: true) */
autorestart?: boolean;
/** List of exit codes that should allow process to stop */
stop_exit_codes?: number[];
/** Minimum uptime before considering process stable */
min_uptime?: number;
/** Maximum restart attempts in unstable period */
max_restarts?: number;
/** Memory restart threshold (e.g., '150M', '1G') */
max_memory_restart?: number | string;
/** Node.js arguments (alias for interpreter_args) */
node_args?: string | string[];
/** Prefix logs with timestamp */
time?: boolean;
/** Wait for ready signal from process */
wait_ready?: boolean;
/** SIGKILL timeout in milliseconds (default: 1600) */
kill_timeout?: number;
/** Delay between restarts in milliseconds */
restart_delay?: number;
/** Script interpreter (default: 'node') */
interpreter?: string;
/** Force start even if process already running */
force?: boolean;
/** Cron pattern for scheduled restarts */
cron?: string;
/** Execute command instead of script */
execute_command?: any;
/** Write process output to files */
write?: any;
/** Enable source map support */
source_map_support?: any;
/** Disable source map support */
disable_source_map_support?: any;
/** Process namespace (default: 'default') */
namespace?: string;
/** Exponential backoff restart delay */
exp_backoff_restart_delay?: number;
/** Listen timeout for reload operations */
listen_timeout?: number;
/** Shutdown using message instead of SIGKILL */
shutdown_with_message?: boolean;
/** Environment variable name incremented for each instance */
increment_var?: string;
/** Instance ID environment variable name */
instance_var?: string;
/** Filter environment variables */
filter_env?: boolean | string | string[];
/** Disable log output */
disable_logs?: boolean;
/** Log output type */
log_type?: string;
/** Container mode for Docker */
container?: boolean;
/** Distribution mode for Docker */
dist?: boolean;
/** Docker image name */
image_name?: string;
/** Node.js version for Docker */
node_version?: string;
/** Fresh install for Docker */
fresh?: boolean;
/** Docker daemon mode */
dockerdaemon?: boolean;
}Complete process information structure returned by PM2.
interface ProcessDescription {
/** Process name as specified in configuration */
name?: string;
/** System process ID */
pid?: number;
/** PM2 internal process ID */
pm_id?: number;
/** Real-time monitoring data */
monit?: Monit;
/** PM2 environment and configuration data */
pm2_env?: Pm2Env;
}Real-time process monitoring data.
interface Monit {
/** Memory usage in bytes */
memory?: number;
/** CPU usage percentage (0-100) */
cpu?: number;
}Complete PM2 environment data for processes.
interface Pm2Env {
/** Process working directory */
pm_cwd?: string;
/** Stdout log file path */
pm_out_log_path?: string;
/** Stderr log file path */
pm_err_log_path?: string;
/** Script interpreter being used */
exec_interpreter?: string;
/** Process uptime in milliseconds */
pm_uptime?: number;
/** Number of unstable restarts */
unstable_restarts?: number;
/** Last restart timestamp */
restart_time?: number;
/** Current process status */
status?: ProcessStatus;
/** Number of instances running */
instances?: number | 'max';
/** Full path to executable script */
pm_exec_path?: string;
}Basic process information returned by lifecycle operations.
interface Proc {
/** Process name */
name?: string;
/** Enable version control integration */
vizion?: boolean;
/** Auto restart on failure */
autorestart?: boolean;
/** Execution mode */
exec_mode?: string;
/** Script interpreter */
exec_interpreter?: string;
/** Executable path */
pm_exec_path?: string;
/** Working directory */
pm_cwd?: string;
/** Number of instances */
instances?: number;
/** Node.js arguments */
node_args?: string[];
/** Stdout log path */
pm_out_log_path?: string;
/** Stderr log path */
pm_err_log_path?: string;
/** PID file path */
pm_pid_path?: string;
/** Current status */
status?: string;
/** Process uptime */
pm_uptime?: number;
/** AXM actions available */
axm_actions?: any[];
/** AXM monitoring data */
axm_monitor?: any;
/** AXM dynamic data */
axm_dynamic?: any;
/** Version control running status */
vizion_running?: boolean;
/** Process creation timestamp */
created_at?: number;
/** PM2 process ID */
pm_id?: number;
/** Number of restarts */
restart_time?: number;
/** Unstable restart count */
unstable_restarts?: number;
/** Started inside PM2 flag */
started_inside?: boolean;
/** Command execution data */
command?: Command;
/** Version control information */
versioning?: any;
/** Process exit code */
exit_code?: number;
}Command execution metadata.
interface Command {
/** Command locked status */
locked?: boolean;
/** Command metadata */
metadata?: any;
/** Command start timestamp */
started_at?: any;
/** Command completion timestamp */
finished_at?: any;
/** Command error information */
error?: any;
}Options for zero-downtime reload operations.
interface ReloadOptions {
/** Update environment variables from process.env before reloading */
updateEnv?: boolean;
}Options for static file serving functionality.
interface ServeOptions {
/** Single Page Application mode - serve index.html for all routes */
spa?: boolean;
/** Basic authentication username */
basic_auth_username?: string;
/** Basic authentication password */
basic_auth_password?: string;
/** Monitor URL path for health checks */
monitor?: string;
}Options for PM2 module installation.
interface InstallOptions {
/** Install from tarball instead of npm */
tarball?: boolean;
/** Perform installation (default: true) */
install?: boolean;
/** Docker mode installation */
docker?: boolean;
/** Use PM2 v1 API compatibility */
v1?: boolean;
/** Safe mode installation with retry attempts */
safe?: boolean | number;
}Options for Docker-related operations.
interface DockerOptions {
/** Docker image name for containerization */
imageName?: string;
/** Node.js version to use in container */
nodeVersion?: string;
/** Perform fresh installation in container */
fresh?: boolean;
/** Force Docker operations */
force?: boolean;
/** Docker daemon mode */
dockerdaemon?: boolean;
}
/**
* Options for module publishing
*/
export interface PublishOptions {
/** Make module public in registry */
public?: boolean;
/** Force publish even if version exists */
force?: boolean;
/** Include development dependencies */
dev?: boolean;
}
/**
* Version control information
*/
export interface VersionInfo {
/** Repository path */
repo_path?: string;
/** Current branch */
branch?: string;
/** Current commit hash */
revision?: string;
/** Commit message */
comment?: string;
/** Last update timestamp */
update_time?: number;
}
/**
* Deployment configuration
*/
export interface DeploymentConfig {
/** SSH user for deployment */
user: string;
/** Target host(s) for deployment */
host: string | string[];
/** Git reference to deploy (branch/tag) */
ref: string;
/** Git repository URL */
repo: string;
/** Deployment path on remote server */
path: string;
/** Commands to run before deployment */
'pre-deploy'?: string;
/** Commands to run after deployment */
'post-deploy'?: string;
/** Commands to run during initial setup */
'pre-setup'?: string;
/** Commands to run after initial setup */
'post-setup'?: string;
}Enumeration of possible process statuses.
type ProcessStatus =
| 'online' // Process running normally
| 'stopping' // Process being stopped
| 'stopped' // Process stopped
| 'launching' // Process being started
| 'errored' // Process crashed/errored
| 'one-launch-status' // One-time launch status
| 'waiting_restart'; // Waiting for restartSupported platforms for startup script generation.
type Platform =
| 'ubuntu' // Ubuntu Linux
| 'centos' // CentOS Linux
| 'redhat' // Red Hat Linux
| 'gentoo' // Gentoo Linux
| 'systemd' // systemd-based systems
| 'darwin' // macOS
| 'amazon'; // Amazon Linux/** Standard error callback */
type ErrCallback = (err: Error) => void;
/** Error callback with process data */
type ErrProcCallback = (err: Error, proc: Proc) => void;
/** Error callback with process description */
type ErrProcDescCallback = (err: Error, processDescription: ProcessDescription) => void;
/** Error callback with process description array */
type ErrProcDescsCallback = (err: Error, processDescriptionList: ProcessDescription[]) => void;
/** Error callback with generic result */
type ErrResultCallback = (err: Error, result: any) => void;
/** Error callback with message bus */
type ErrBusCallback = (err: Error, bus: any) => void;Complete function signatures for all PM2 API methods with proper TypeScript typing.
// Connection Management
function connect(callback: ErrCallback): void;
function connect(noDaemonMode: boolean, callback: ErrCallback): void;
function disconnect(): void;
// Process Lifecycle
function start(options: StartOptions, callback: ErrProcCallback): void;
function start(script: string, callback: ErrProcCallback): void;
function start(script: string, options: StartOptions, callback: ErrProcCallback): void;
function start(jsonConfigFile: string, callback: ErrProcCallback): void;
function stop(process: string | number, callback: ErrProcCallback): void;
function restart(process: string | number, callback: ErrProcCallback): void;
function reload(process: string | number, callback: ErrProcCallback): void;
function reload(process: string | number, options: ReloadOptions, callback: ErrProcCallback): void;
function delete(process: string | number, callback: ErrProcCallback): void;
// Process Information
function list(callback: ErrProcDescsCallback): void;
function describe(process: string | number, callback: ErrProcDescsCallback): void;
function getPID(app_name?: string, callback?: ErrProcCallback): void;
// Configuration
function get(key?: string, callback?: ErrCallback): void;
function set(key: string, value: any, callback?: ErrCallback): void;
function multiset(values: string, callback?: ErrCallback): void;
function unset(key: string, callback?: ErrCallback): void;
// State Management
function dump(callback: ErrResultCallback): void;
function resurrect(callback: ErrResultCallback): void;
// Monitoring and Communication
function launchSysMonitoring(callback?: ErrCallback): void;
function launchBus(callback: ErrBusCallback): void;
function profile(type: 'cpu' | 'mem', time?: number, callback?: ErrCallback): void;
function sendDataToProcessId(proc_id: number, packet: object, callback: ErrResultCallback): void;
function sendLineToStdin(pm_id: string | number, line: string, separator?: string, callback?: ErrCallback): void;
function trigger(pm_id: string | number, action_name: string, params?: any, callback?: ErrCallback): void;
function sendSignalToProcessName(signal: string | number, process: number | string, callback: ErrResultCallback): void;
// System Integration
function startup(platform: Platform, callback: ErrResultCallback): void;
function killDaemon(callback: ErrProcDescCallback): void;
// Utilities
function serve(path?: string, port?: number, options?: ServeOptions, callback?: ErrCallback): void;
function install(module_name: string, options?: InstallOptions, callback?: ErrCallback): void;
function uninstall(module_name: string, callback?: ErrCallback): void;
function env(app_id: string | number, callback?: ErrCallback): void;
function inspect(app_name: string, callback?: ErrCallback): void;
function attach(pm_id: string | number, separator?: string, callback?: ErrCallback): void;
function flush(process: number | string, callback: ErrResultCallback): void;
function reloadLogs(callback: ErrResultCallback): void;
// State Persistence
function dump(callback: ErrResultCallback): void;
function resurrect(callback: ErrResultCallback): void;
function clearDump(callback: ErrResultCallback): void;
function autodump(callback: ErrResultCallback): void;
// Module Management
function deleteModule(module_name: string, callback?: ErrCallback): void;
function generateModuleSample(app_name: string, callback?: ErrCallback): void;
function package(module_path: string, callback?: ErrCallback): void;
function publish(folder: string, options?: PublishOptions, callback?: ErrCallback): void;
// Version Control Integration
function pullAndRestart(process_name: string, callback?: ErrResultCallback): void;
function pullAndReload(process_name: string, callback?: ErrResultCallback): void;
function pullCommitId(process_name: string, commit_id: string, callback?: ErrResultCallback): void;
function backward(process_name: string, callback?: ErrResultCallback): void;
function forward(process_name: string, callback?: ErrResultCallback): void;
// Docker Integration
function generateDockerfile(script: string, options?: DockerOptions): string;
function dockerMode(script: string, options?: DockerOptions, mode?: string): any;
// System Information
function getVersion(callback?: ErrCallback): void;
function report(): void;
function ping(callback?: ErrCallback): void;
function update(callback?: ErrCallback): void;
// Extended Signal Management
function sendSignalToProcessId(signal: string | number, process_id: number, callback: ErrResultCallback): void;import * as pm2 from 'pm2';
import { StartOptions, ProcessDescription } from 'pm2';
const startOptions: StartOptions = {
name: 'my-app',
script: './app.js',
instances: 'max' as any, // instances can be number or 'max'
exec_mode: 'cluster',
env: {
NODE_ENV: 'production',
PORT: '3000'
},
watch: true,
ignore_watch: ['node_modules', 'logs'],
max_memory_restart: '1G',
autorestart: true,
max_restarts: 5,
min_uptime: 10000
};
pm2.connect((err: Error) => {
if (err) {
console.error('Connection error:', err);
process.exit(2);
}
pm2.start(startOptions, (err: Error, proc) => {
if (err) {
console.error('Start error:', err);
return pm2.disconnect();
}
console.log('Process started:', proc[0].name);
pm2.disconnect();
});
});pm2.list((err: Error, processes: ProcessDescription[]) => {
if (err) throw err;
processes.forEach((proc: ProcessDescription) => {
console.log(`Process: ${proc.name}`);
console.log(` Status: ${proc.pm2_env?.status}`);
console.log(` Memory: ${proc.monit?.memory} bytes`);
console.log(` CPU: ${proc.monit?.cpu}%`);
console.log(` Uptime: ${proc.pm2_env?.pm_uptime}ms`);
});
});import { ServeOptions } from 'pm2';
const serveOptions: ServeOptions = {
spa: true,
basic_auth_username: 'admin',
basic_auth_password: 'secret',
monitor: '/health'
};
pm2.serve('./public', 8080, serveOptions, (err: Error) => {
if (err) throw err;
console.log('Static server started with SPA support');
});Complete module declaration for PM2 TypeScript support.
declare module 'pm2' {
// Export all interfaces and types
export interface StartOptions { /* ... */ }
export interface ProcessDescription { /* ... */ }
export interface Monit { /* ... */ }
export interface Pm2Env { /* ... */ }
export interface Proc { /* ... */ }
export interface Command { /* ... */ }
export interface ReloadOptions { /* ... */ }
export interface ServeOptions { /* ... */ }
export interface InstallOptions { /* ... */ }
export interface DockerOptions { /* ... */ }
export type ProcessStatus = 'online' | 'stopping' | 'stopped' | 'launching' | 'errored' | 'one-launch-status' | 'waiting_restart';
export type Platform = 'ubuntu' | 'centos' | 'redhat' | 'gentoo' | 'systemd' | 'darwin' | 'amazon';
// Export all callback types
export type ErrCallback = (err: Error) => void;
export type ErrProcCallback = (err: Error, proc: Proc) => void;
export type ErrProcDescCallback = (err: Error, processDescription: ProcessDescription) => void;
export type ErrProcDescsCallback = (err: Error, processDescriptionList: ProcessDescription[]) => void;
export type ErrResultCallback = (err: Error, result: any) => void;
export type ErrBusCallback = (err: Error, bus: any) => void;
// Export all API functions
export function connect(callback: ErrCallback): void;
export function connect(noDaemonMode: boolean, callback: ErrCallback): void;
export function disconnect(): void;
export function start(options: StartOptions, callback: ErrProcCallback): void;
export function start(script: string, callback: ErrProcCallback): void;
export function start(script: string, options: StartOptions, callback: ErrProcCallback): void;
export function start(jsonConfigFile: string, callback: ErrProcCallback): void;
// ... all other function exports
// Custom API class export
export const custom: any;
}Install with Tessl CLI
npx tessl i tessl/npm-pm2