Manage Node Apps Using PM2

Install PM2

1
npm install pm2 -g

Manage Apps using PM2

Start a new app

1
pm2 start npm --name "app-name" -- start

Start a node app using npm start PM2 start a node app

Start an Angular app using ng serve

1
pm2 start "ng serve --host 0.0.0.0 --disableHostCheck true --port 8004 --poll 500" --name "angular-app"

List all apps

1
pm2 list

Stop an app

1
pm2 stop <app-name OR app-id>

Restart an app

1
pm2 restart <app-name OR app-id>

Delete an app

1
pm2 delete <app-name OR app-id>

Monitor Apps using PM2

Monitor all apps

1
pm2 monit

Monitor a specific app

1
pm2 monit <app-name OR app-id>

PM2 Monitor

List current PM2 apps

1
pm2 list

Save PM2 apps list

1
pm2 save

Troubleshooting

PM2 is not syncing with the latest changes

1
pm2 startup

Mac OS X’s result

1
2
3
> [PM2] Init System found: launchd
> [PM2] To setup the Startup Script, copy/paste the following command:
> sudo env PATH=$PATH:/opt/homebrew/Cellar/node/19.0.1/bin /opt/homebrew/lib/node_modules/pm2/bin/pm2 startup launchd -u hain --hp /Users/hain

Run this command to fix the issue

1
sudo env PATH=$PATH:/opt/homebrew/Cellar/node/19.0.1/bin /opt/homebrew/lib/node_modules/pm2/bin/pm2 startup launchd -u hain --hp /Users/hain