PM2 Node.js Process Management - mhulse/mhulse.github.io GitHub Wiki
You can use PM2 to manage Node.js apps:
Advanced, production process manager for Node.js
http://pm2.keymetrics.io/
Note: PM2 is connected to user; on multi-user boxes, PM2 can be run as root; if you login to the server under your own username (e.g., production server), and you want to PM2 manage Node apps on that server, run sudo -i
before running any of the pm2
commands below.
# To start a node process using PM2, navigate to the app's server.js (or whatever file is the main server JS file):
$ cd <this repo>/server/server.js
# … and run:
$ pm2 start server.js --name site.com --watch
# Restart a node process by name:
$ pm2 restart site.com
# Restart process by id, and rename it:
$ pm2 restart 3 --name new-name --watch
# To save your list of running apps so they start when server gets restarted:
$ pm2 save
# Make sure pm2 starts on server boot using “init system” for server (this example is CentOS):
$ pm2 startup systemd
# If --watch is enabled, stopping it won’t stop watching! You must do:
$ pm2 stop site.com --watch 0
# If you have saved your list of PM2 processes in the past, and they are not listed, you can re-initialize them:
$ pm2 resurrect
# To view running apps (should be root user, but may be others):
$ pm2 list
# See details of a process (0 = <process-name|process-id>):
$ pm2 show 0
# Remove app from PM2:
$ pm2 delete site.com
# To view all app/process logs:
$ pm2 log --lines 500
# Or, view a specific app/process via process-name:
$ pm2 logs site.com --lines 500
# More information about a specific application:
$ pm2 info site.com
# Display the application status, CPU, and memory usage:
$ pm2 monit