PM2 is a daemon process manager that will help you manage and keep your application online. Getting started with PM2 is straightforward, it is offered as a simple and intuitive CLI, installable via NPM.
The latest PM2 version is installable with NPM or Yarn:
npm install pm2@latest -g
# or
yarn global add pm2
To install Node.js and NPM you can use NVM
The simplest way to start, daemonize and monitor your application is by using this command line:
pm2 start app.js
Or start any other application easily:
pm2 start bashscript.sh
pm2 start python-app.py --watch
pm2 start binary-file -- --port 1520
Some options you can pass to the CLI:
# Specify an app name
--name <app_name>
# Watch and Restart app when files change
--watch
# Set memory threshold for app reload
--max-memory-restart <200MB>
# Specify log file
--log <log_path>
# Pass extra arguments to the script
-- arg1 arg2 arg3
# Delay between automatic restarts
--restart-delay <delay in ms>
# Prefix logs with time
--time
# Do not auto restart app
--no-autorestart
# Specify cron for forced restart
--cron <cron_pattern>
# Attach to application log
--no-daemon
As you can see many options are available to manage your application with PM2. You will discover them depending on your use case.
Managing application state is simple here are the commands:
pm2 restart app_name
pm2 reload app_name
pm2 stop app_name
pm2 delete app_name
Instead of app_name you can pass:
Now that you have started this application, you can check its status, logs, metrics and even get the online dashboard with pm2.io.
List managed applications
pm2 [list|ls|status]
To display logs in realtime:
pm2 logs
To dig in older logs:
pm2 logs --lines 200
Here is a realtime dashboard that fits directly into your terminal:
pm2 monit
Web based dashboard, cross servers with diagnostic system:
pm2 plus
Sources: Quick Start | PM2.IO Web App
Add a comment