Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to watch and reload an ExpressJS app with pm2

I'm developing an ExpressJS app. I use pm2 to load it:

myapp$ pm2 start bin/www

This works fine, except that adding the --watch flag doesn't seem to work; every time I change the JS source I need to explicitly restart it for my changes to take effect:

myapp$ pm2 restart www

What am I doing wrong? I've tried the --watch flag with a non-ExpressJS app and it worked as expected.

like image 744
John J. Camilleri Avatar asked Feb 13 '15 14:02

John J. Camilleri


1 Answers

I never managed to make default watch settings work in Ubuntu, however using polling via advanced watch options worked:

  "watch":  true,
  "ignore_watch" : ["node_modules"],
  "watch_options": {
    "usePolling": true,
    "interval": 1000
  }

More info:

https://github.com/buunguyen/PM2/blob/master/ADVANCED_README.md#watch--restart

https://github.com/paulmillr/chokidar#api

like image 52
user3136781 Avatar answered Nov 15 '22 23:11

user3136781