Skip to content

pm2

About 307 wordsAbout 1 min

2021-09-20

Start

Start the node process

pm2 start app.js

pm2 ping # Make sure the pm2 daemon is started

Start other applications

pm2 start bash.sh
pm2 start python-app.py --watch
pm2 start binary-file -- --port 1520

Process management

pm2 restart app_name # Restart app_name
pm2 reload app_name # Reload app_name
pm2 stop app_name # Stop app_name
pm2 delete app_name # delete app_name

You can replace app_name with:

  • all: for all processes
  • id: for a process with a specific id

Check Status

List all application statuses of PM2

pm2 [list|ls|status]

pm2 list # show all process statuses
pm2 jlist # print process list in raw JSON format
pm2 prettylist # print process list in pretty JSON format
pm2 describe 0 # show all information about a specific process

Logs

pm2 logs
pm2 logs --lines 200 # old logs
pm2 flush # clear all log files
pm2 reloadLogs # reload all logs

Terminal Dashboard

pm2 monit

Web Dashboard

pm2 plus

Cluster mode

# 0 / max means starting multiple processes based on the number of CPUs
pm2 start app.js -i 0
pm2 start app.js -i max # Equivalent to 0, deprecated

Common command line parameters

--name <app_name> # Specify the application name
--watch # Watch for file updates and restart the application
--max-memory-restart <200MB> # Set the maximum memory threshold for application reload
--log <log_path> # Specify the log path
--restart-delay <delay in ms> # Delay between automatic restarts
--time # Log with time prefix
--no-autorestart # Do not automatically restart
--cron <cron_pattern> # Specify cron Force restart

Update PM2

npm install pm2@latest -g
pm2 update # Update pm2 in memory