pm2
- Version 6.0.13
- Published
- 838 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
- attach()
- connect()
- delete()
- describe()
- disconnect()
- dump()
- env()
- flush()
- get()
- getPID()
- inspect()
- install()
- killDaemon()
- launchBus()
- launchSysMonitoring()
- list()
- multiset()
- profile()
- reload()
- reloadLogs()
- restart()
- sendDataToProcessId()
- sendLineToStdin()
- sendSignalToProcessName()
- serve()
- set()
- start()
- startup()
- stop()
- trigger()
- uninstall()
- unset()
Interfaces
StartOptions
- args
- autorestart
- autostart
- container
- cron
- cwd
- disable_logs
- disable_source_map_support
- dist
- dockerdaemon
- env
- error
- exec_mode
- execute_command
- exp_backoff_restart_delay
- filter_env
- force
- fresh
- ignore_watch
- image_name
- increment_var
- instance_var
- instances
- interpreter
- interpreter_args
- kill_timeout
- listen_timeout
- log_date_format
- log_type
- max_memory_restart
- max_restarts
- merge_logs
- min_uptime
- name
- namespace
- node_args
- node_version
- output
- pid
- restart_delay
- script
- shutdown_with_message
- source_map_support
- stop_exit_codes
- time
- wait_ready
- watch
- write
Functions
function attach
attach: ( pm_id: string | number, separator?: string, errback?: ErrCallback) => void;
Attach to process logs
Parameter pm_id
Process id
Parameter separator
Log separator
Parameter errback
Called when attached
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 env
env: (app_id: string | number, errback?: ErrCallback) => void;
Get process environment variables
Parameter app_id
Process name or id
Parameter errback
Called with environment variables
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 get
get: (key?: string, errback?: ErrCallback) => void;
Get PM2 configuration value
Parameter key
Configuration key (optional, returns all config if not provided)
Parameter errback
Called with configuration value
function getPID
getPID: (app_name?: string, errback?: ErrProcCallback) => void;
Get process PID
Parameter app_name
Process name (optional, returns all PIDs if not provided)
Parameter errback
Called with PID information
function inspect
inspect: (app_name: string, errback?: ErrCallback) => void;
Inspect a process (debugging)
Parameter app_name
Process name
Parameter errback
Called with inspect information
function install
install: ( module_name: string, options?: InstallOptions, errback?: ErrCallback) => void;
Install a PM2 module
Parameter module_name
Name of the module to install
Parameter options
Installation options
Parameter errback
Called when installation completes
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 launchSysMonitoring
launchSysMonitoring: (errback?: ErrCallback) => void;
Launch system monitoring (CPU, Memory usage)
Parameter errback
Called when monitoring is launched
function list
list: (errback: ErrProcDescsCallback) => void;
Gets the list of running processes being managed by pm2.
Parameter errback
function multiset
multiset: (values: string, errback?: ErrCallback) => void;
Set multiple PM2 configuration values
Parameter values
Configuration values as string
Parameter errback
Called when values are set
function profile
profile: (type: 'cpu' | 'mem', time?: number, errback?: ErrCallback) => void;
Profile CPU or Memory usage
Parameter type
'cpu' for CPU profiling, 'mem' for memory profiling
Parameter time
Duration in seconds (default: 10)
Parameter errback
Called when profiling is complete
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; (packet: { id: number; type: 'process:msg'; topic: true; data: object }): void;};
- Send an set of data as object to a specific process
Parameter proc_id
Parameter packet
Parameter cb
- Send an set of data as object to a specific process
Parameter packet
function sendLineToStdin
sendLineToStdin: ( pm_id: string | number, line: string, separator?: string, errback?: ErrCallback) => void;
Send line to process stdin
Parameter pm_id
Process id
Parameter line
Line to send
Parameter separator
Line separator (default: '\n')
Parameter errback
Called when line is sent
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 serve
serve: ( path?: string, port?: number, options?: ServeOptions, errback?: ErrCallback) => void;
Serve static files
Parameter path
Path to serve files from
Parameter port
Port number (default: 8080)
Parameter options
Serve options
Parameter errback
Called when server starts
function set
set: (key: string, value: any, errback?: ErrCallback) => void;
Set PM2 configuration value
Parameter key
Configuration key
Parameter value
Configuration value
Parameter errback
Called when value is set
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
function trigger
trigger: ( pm_id: string | number, action_name: string, params?: any, errback?: ErrCallback) => void;
Trigger a custom action on a process
Parameter pm_id
Process id
Parameter action_name
Name of the action to trigger
Parameter params
Parameters to pass to the action
Parameter errback
Called when action completes
function uninstall
uninstall: (module_name: string, errback?: ErrCallback) => void;
Uninstall a PM2 module
Parameter module_name
Name of the module to uninstall
Parameter errback
Called when uninstallation completes
function unset
unset: (key: string, errback?: ErrCallback) => void;
Unset PM2 configuration value
Parameter key
Configuration key to unset
Parameter errback
Called when value is unset
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 DockerOptions
interface DockerOptions {}
Options for Docker operations
property dockerdaemon
dockerdaemon?: boolean;
(Default: false) Docker daemon mode
property force
force?: boolean;
(Default: false) Force operation
property fresh
fresh?: boolean;
(Default: false) Fresh installation
property imageName
imageName?: string;
Docker image name
property nodeVersion
nodeVersion?: string;
Node.js version to use
interface InstallOptions
interface InstallOptions {}
Options for module installation
property docker
docker?: boolean;
(Default: false) Docker mode
property install
install?: boolean;
(Default: true) Perform installation
property safe
safe?: boolean | number;
(Default: false) Safe mode installation
property tarball
tarball?: boolean;
(Default: false) Install from tarball
property v1
v1?: boolean;
(Default: false) Use v1 API
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 ServeOptions
interface ServeOptions {}
Options for serving static files
property basic_auth_password
basic_auth_password?: string;
Basic authentication password
property basic_auth_username
basic_auth_username?: string;
Basic authentication username
property monitor
monitor?: string;
Monitor URL path
property spa
spa?: boolean;
(Default: false) Single Page Application mode
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 container
container?: boolean;
(Default: false) Enable container mode.
property cron
cron?: any;
property cwd
cwd?: string;
The working directory to start the process with.
property disable_logs
disable_logs?: boolean;
(Default: false) Disable logs output.
property disable_source_map_support
disable_source_map_support?: any;
property dist
dist?: boolean;
(Default: false) Distribution mode for Docker.
property dockerdaemon
dockerdaemon?: boolean;
(Default: false) Docker daemon mode.
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 exp_backoff_restart_delay
exp_backoff_restart_delay?: number;
(Default: false) Exponential backoff restart delay in milliseconds. When enabled, PM2 will progressively increase restart delays after failures.
property filter_env
filter_env?: boolean | string | string[];
Filter out specific environment variables from the process. Can be true to filter all, or array/string of specific variables.
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 fresh
fresh?: boolean;
(Default: false) Fresh install for Docker.
property ignore_watch
ignore_watch?: string[];
property image_name
image_name?: string;
Docker image name.
property increment_var
increment_var?: string;
Environment variable name that gets incremented for each cluster instance.
property instance_var
instance_var?: string;
Name of the environment variable holding the instance ID. 'NODE_APP_INSTANCE'
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 listen_timeout
listen_timeout?: number;
Timeout for application to be ready after reload (in milliseconds).
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 log_type
log_type?: string;
Log output type.
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 node_version
node_version?: string;
Node.js version for Docker container.
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 shutdown_with_message
shutdown_with_message?: boolean;
(Default: false) If true, shutdown the process using process.send('shutdown') instead of process.kill().
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 oneto 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[](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>
- Updated .
Package analyzed in 2146 ms. - Missing or incorrect documentation? Open an issue for this package.