Published on October 23rd, 2019
Long story short. I have made script for scraping some stuff and put it on the DigitalOcean droplet and as I had problems with crashing (*cough poorly written code), I have found this process manager called PM2 (Process Manager 2). Heard about it long time but never got to use one. Oh, boy! It’s awesome.
Like any other npm module.
npm i pm2 -g
pm2 start app.js --name "your_app_name" # next time start app with pm2 start your_app_name
pm2 stop your_app_name
pm2 delete your_app_name
You can also use
all instead of app name to do operation on all processes
See list of all running processes.
View dashboard with live info from processes.
pm2 monit # this is not a typo
You can pass argument to pm2 to enhance your experience.
Pass arguments to your app.
-- arg1 arg2 arg3
Save console logs to file.
--log path/to/file # you can also prefix logs with time if you add --time
Restart app on file change.
Restart when app reaches memory limit.
Restart on cron job.