pm2

  • Version 5.4.3
  • Published
  • 797 kB
  • 29 dependencies
  • AGPL-3.0 license

Install

npm i pm2
yarn add pm2
pnpm add pm2

Overview

Production process manager for Node.JS applications with a built-in load balancer.

Index

Functions

function connect

connect: {
(errback: ErrCallback): void;
(noDaemonMode: boolean, errback: ErrCallback): void;
};
  • Either connects to a running pm2 daemon (“God”) or launches and daemonizes one. Once launched, the pm2 process will keep running after the script exits.

    Parameter errback

    Called when finished connecting to or launching the pm2 daemon process.

  • Either connects to a running pm2 daemon (“God”) or launches and daemonizes one. Once launched, the pm2 process will keep running after the script exits.

    Parameter noDaemonMode

    (Default: false) If true is passed for the first argument pm2 will not be run as a daemon and will die when the related script exits. By default, pm2 stays alive after your script exits. If pm2 is already running, your script will link to the existing daemon but will die once your process exits.

    Parameter errback

    Called when finished connecting to or launching the pm2 daemon process.

function delete

delete: (process: string | number, errback: ErrProcCallback) => void
  • Stops the process and removes it from pm2’s list. The process will no longer be accessible by its name

    Parameter process

    Can either be the name as given in the pm2.start options, a process id, or the string “all” to indicate that all scripts should be restarted.

    Parameter errback

    called when the process is deleted

function describe

describe: (process: string | number, errback: ErrProcDescsCallback) => void;
  • Returns various information about a process: eg what stdout/stderr and pid files are used.

    Parameter process

    Can either be the name as given in the pm2.start options, a process id, or the string “all” to indicate that all scripts should be restarted.

    Parameter errback

function disconnect

disconnect: () => void;
  • Disconnects from the pm2 daemon.

function dump

dump: { (errback: ErrResultCallback): void; (errback: ErrResultCallback): void };
  • Writes the process list to a json file at the path in the DUMP_FILE_PATH environment variable (“~/.pm2/dump.pm2” by default).

    Parameter errback

  • Parameter errback

function flush

flush: (process: number | string, errback: ErrResultCallback) => void;
  • Flushes the logs.

    Parameter process

    Can either be the name as given in the pm2.start options, a process id, or the string “all” to indicate that all scripts should be restarted.

    Parameter errback

function killDaemon

killDaemon: (errback: ErrProcDescCallback) => void;
  • Kills the pm2 daemon (same as pm2 kill). Note that when the daemon is killed, all its processes are also killed. Also note that you still have to explicitly disconnect from the daemon even after you kill it.

    Parameter errback

function launchBus

launchBus: (errback: ErrBusCallback) => void;
  • Opens a message bus.

    Parameter errback

    The bus will be an Axon Sub Emitter object used to listen to and send events.

function list

list: (errback: ErrProcDescsCallback) => void;
  • Gets the list of running processes being managed by pm2.

    Parameter errback

function reload

reload: {
(process: string | number, errback: ErrProcCallback): void;
(
process: string | number,
options: ReloadOptions,
errback: ErrProcCallback
): void;
};
  • Zero-downtime rolling restart. At least one process will be kept running at all times as each instance is restarted individually. Only works for scripts started in cluster mode.

    Parameter process

    Can either be the name as given in the pm2.start options, a process id, or the string “all” to indicate that all scripts should be restarted.

    Parameter errback

    called when the process is reloaded

  • Zero-downtime rolling restart. At least one process will be kept running at all times as each instance is restarted individually. Only works for scripts started in cluster mode.

    Parameter process

    Can either be the name as given in the pm2.start options, a process id, or the string “all” to indicate that all scripts should be restarted.

    Parameter options

    An object containing configuration

    Parameter

    options.updateEnv - (Default: false) If true is passed in, pm2 will reload it’s environment from process.env before reloading your process.

    Parameter errback

    called when the process is reloaded

function reloadLogs

reloadLogs: (errback: ErrResultCallback) => void;
  • Rotates the log files. The new log file will have a higher number in it (the default format being ${process.name}-${out|err}-${number}.log).

    Parameter errback

function restart

restart: (process: string | number, errback: ErrProcCallback) => void;
  • Stops and restarts the process.

    Parameter process

    Can either be the name as given in the pm2.start options, a process id, or the string “all” to indicate that all scripts should be restarted.

    Parameter errback

    called when the process is restarted

function sendDataToProcessId

sendDataToProcessId: (
proc_id: number,
packet: object,
cb: ErrResultCallback
) => void;
  • - Send an set of data as object to a specific process

    Parameter proc_id

    Parameter packet

    Parameter cb

function sendSignalToProcessName

sendSignalToProcessName: (
signal: string | number,
process: number | string,
errback: ErrResultCallback
) => void;
  • Parameter signal

    Parameter process

    Can either be the name as given in the pm2.start options, a process id, or the string “all” to indicate that all scripts should be restarted.

    Parameter errback

function start

start: {
(options: StartOptions, errback: ErrProcCallback): void;
(jsonConfigFile: string, errback: ErrProcCallback): void;
(script: string, errback: ErrProcCallback): void;
(script: string, options: StartOptions, errback: ErrProcCallback): void;
(script: string, jsonConfigFile: string, errback: ErrProcCallback): void;
};
  • Starts a script that will be managed by pm2.

    Parameter options

    Options

    Parameter errback

    An errback called when the script has been started. The proc parameter will be a pm2 process object.

  • Starts a script that will be managed by pm2.

    Parameter jsonConfigFile

    The path to a JSON file that can contain the same options as the options parameter.

    Parameter errback

    An errback called when the script has been started. The proc parameter will be a pm2 process object.

  • Starts a script that will be managed by pm2.

    Parameter script

    The path of the script to run.

    Parameter errback

    An errback called when the script has been started. The proc parameter will be a pm2 process object.

  • Starts a script that will be managed by pm2.

    Parameter script

    The path of the script to run.

    Parameter options

    Options

    Parameter errback

    An errback called when the script has been started. The proc parameter will be a pm2 process object.

  • Starts a script that will be managed by pm2.

    Parameter script

    The path of the script to run.

    Parameter jsonConfigFile

    The path to a JSON file that can contain the same options as the options parameter.

    Parameter errback

    An errback called when the script has been started. The proc parameter will be a pm2 process object.

function startup

startup: (platform: Platform, errback: ErrResultCallback) => void;
  • - Registers the script as a process that will start on machine boot. The current process list will be dumped and saved for resurrection on reboot.

    Parameter platform

    Parameter errback

function stop

stop: (process: string | number, errback: ErrProcCallback) => void;
  • Stops a process but leaves the process meta-data in pm2’s list

    Parameter process

    Can either be the name as given in the pm2.start options, a process id, or the string “all” to indicate that all scripts should be restarted.

    Parameter errback

    called when the process is stopped

Interfaces

interface Command

interface Command {}

    property error

    error?: any;

      property finished_at

      finished_at?: any;

        property locked

        locked?: boolean;

          property metadata

          metadata?: any;

            property started_at

            started_at?: any;

              interface Proc

              interface Proc {}

                property autorestart

                autorestart?: boolean;

                  property axm_actions

                  axm_actions?: any[];

                    property axm_dynamic

                    axm_dynamic?: any;

                      property axm_monitor

                      axm_monitor?: any;

                        property command

                        command?: Command;

                          property created_at

                          created_at?: number;

                            property exec_interpreter

                            exec_interpreter?: string;

                              property exec_mode

                              exec_mode?: string;

                                property exit_code

                                exit_code?: number;

                                  property instances

                                  instances?: number;

                                    property name

                                    name?: string;

                                      property node_args

                                      node_args?: string[];

                                        property pm_cwd

                                        pm_cwd?: string;

                                          property pm_err_log_path

                                          pm_err_log_path?: string;

                                            property pm_exec_path

                                            pm_exec_path?: string;

                                              property pm_id

                                              pm_id?: number;

                                                property pm_out_log_path

                                                pm_out_log_path?: string;

                                                  property pm_pid_path

                                                  pm_pid_path?: string;

                                                    property pm_uptime

                                                    pm_uptime?: number;

                                                      property restart_time

                                                      restart_time?: number;

                                                        property started_inside

                                                        started_inside?: boolean;

                                                          property status

                                                          status?: string;

                                                            property unstable_restarts

                                                            unstable_restarts?: number;

                                                              property versioning

                                                              versioning?: any;

                                                                property vizion

                                                                vizion?: boolean;

                                                                  property vizion_running

                                                                  vizion_running?: boolean;

                                                                    interface ProcessDescription

                                                                    interface ProcessDescription {}
                                                                    • An object with information about the process.

                                                                    property monit

                                                                    monit?: Monit;

                                                                      property name

                                                                      name?: string;
                                                                      • The name given in the original start command.

                                                                      property pid

                                                                      pid?: number;
                                                                      • The pid of the process.

                                                                      property pm_id

                                                                      pm_id?: number;
                                                                      • The pid for the pm2 God daemon process.

                                                                      property pm2_env

                                                                      pm2_env?: Pm2Env;
                                                                      • The list of path variables in the process’s environment

                                                                      interface StartOptions

                                                                      interface StartOptions {}

                                                                        property args

                                                                        args?: string | string[];
                                                                        • A string or array of strings composed of arguments to pass to the script.

                                                                        property autorestart

                                                                        autorestart?: boolean;
                                                                        • Enable or disable auto restart after process failure (default: true).

                                                                        property autostart

                                                                        autostart?: boolean;
                                                                        • Enable or disable auto start after process added (default: true).

                                                                        property cron

                                                                        cron?: any;

                                                                          property cwd

                                                                          cwd?: string;
                                                                          • The working directory to start the process with.

                                                                          property disable_source_map_support

                                                                          disable_source_map_support?: any;

                                                                            property env

                                                                            env?: { [key: string]: string };
                                                                            • The environment variables to pass on to the process.

                                                                            property error

                                                                            error?: string;
                                                                            • (Default: “~/.pm2/logs/app_name-error.err”) The path to a file to append stderr output to. Can be the same file as output.

                                                                            property exec_mode

                                                                            exec_mode?: string;
                                                                            • (Default: ‘fork’) If sets to ‘cluster’, will enable clustering (running multiple instances of the script).

                                                                            property execute_command

                                                                            execute_command?: any;

                                                                              property force

                                                                              force?: boolean;
                                                                              • (Default: false) By default, pm2 will only start a script if that script isn’t already running (a script is a path to an application, not the name of an application already running). If force is set to true, pm2 will start a new instance of that script.

                                                                              property ignore_watch

                                                                              ignore_watch?: string[];

                                                                                property instances

                                                                                instances?: number;
                                                                                • (Default: 1) How many instances of script to create. Only relevant in exec_mode ‘cluster’.

                                                                                property interpreter

                                                                                interpreter?: string;
                                                                                • (Default: “node”) The interpreter for your script (eg “python”, “ruby”, “bash”, etc). The value “none” will execute the ‘script’ as a binary executable.

                                                                                property interpreter_args

                                                                                interpreter_args?: string | string[];
                                                                                • A string or array of strings composed of arguments to call the interpreter process with. Eg “–harmony” or [”–harmony”,”–debug”]. Only applies if interpreter is something other than “none” (its “node” by default).

                                                                                property kill_timeout

                                                                                kill_timeout?: number;
                                                                                • (Default: 1600) The number of milliseconds to wait after a stop or restart command issues a SIGINT signal to kill the script forceably with a SIGKILL signal.

                                                                                property log_date_format

                                                                                log_date_format?: string;
                                                                                • The display format for log timestamps (eg “YYYY-MM-DD HH:mm Z”). The format is a moment display format.

                                                                                property max_memory_restart

                                                                                max_memory_restart?: number | string;
                                                                                • If sets and script’s memory usage goes about the configured number, pm2 restarts the script. Uses human-friendly suffixes: ‘K’ for kilobytes, ‘M’ for megabytes, ‘G’ for gigabytes’, etc. Eg “150M”.

                                                                                property max_restarts

                                                                                max_restarts?: number;
                                                                                • The maximum number of times in a row a script will be restarted if it exits in less than min_uptime.

                                                                                property merge_logs

                                                                                merge_logs?: boolean;
                                                                                • (Default: false) If true, merges the log files for all instances of script into one stderr log and one stdout log. Only applies in ‘cluster’ mode. For example, if you have 4 instances of ‘test.js’ started via pm2, normally you would have 4 stdout log files and 4 stderr log files, but with this option set to true you would only have one stdout file and one stderr file.

                                                                                property min_uptime

                                                                                min_uptime?: number;
                                                                                • The minimum uptime of the script before it’s considered successfully started.

                                                                                property name

                                                                                name?: string;
                                                                                • An arbitrary name that can be used to interact with (e.g. restart) the process later in other commands. Defaults to the script name without its extension (eg “testScript” for “testScript.js”)

                                                                                property namespace

                                                                                namespace?: string;
                                                                                • NameSpace for the process 'default'

                                                                                  Example 1

                                                                                  'production'

                                                                                  Example 2

                                                                                  'development'

                                                                                  Example 3

                                                                                  'staging'

                                                                                property node_args

                                                                                node_args?: string | string[];
                                                                                • Arguments to pass to the interpreter

                                                                                property output

                                                                                output?: string;
                                                                                • (Default: “~/.pm2/logs/app_name-out.log”) The path to a file to append stdout output to. Can be the same file as error.

                                                                                property pid

                                                                                pid?: string;
                                                                                • Default: “~/.pm2/logs/~/.pm2/pids/app_name-id.pid”) The path to a file to write the pid of the started process. The file will be overwritten. Note that the file is not used in any way by pm2 and so the user is free to manipulate or remove that file at any time. The file will be deleted when the process is stopped or the daemon killed.

                                                                                property restart_delay

                                                                                restart_delay?: number;
                                                                                • (Default: 0) Number of millseconds to wait before restarting a script that has exited.

                                                                                property script

                                                                                script?: string;
                                                                                • The path of the script to run

                                                                                property source_map_support

                                                                                source_map_support?: any;

                                                                                  property stop_exit_codes

                                                                                  stop_exit_codes?: number[];
                                                                                  • List of exit codes that should allow the process to stop (skip autorestart).

                                                                                  property time

                                                                                  time?: boolean;
                                                                                  • Prefix logs with time

                                                                                  property wait_ready

                                                                                  wait_ready?: boolean;
                                                                                  • This will make PM2 listen for that event. In your application you will need to add process.send('ready'); when you want your application to be considered as ready.

                                                                                  property watch

                                                                                  watch?: boolean | string[];
                                                                                  • If set to true, the application will be restarted on change of the script file.

                                                                                  property write

                                                                                  write?: any;

                                                                                    Package Files (1)

                                                                                    Dependencies (29)

                                                                                    Dev Dependencies (2)

                                                                                    Peer Dependencies (0)

                                                                                    No peer dependencies.

                                                                                    Badge

                                                                                    To add a badge like this onejsDocs.io badgeto your package's README, use the codes available below.

                                                                                    You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/pm2.

                                                                                    • Markdown
                                                                                      [![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/pm2)
                                                                                    • HTML
                                                                                      <a href="https://www.jsdocs.io/package/pm2"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>