How to watch and reload an ExpressJS app with pm2

John J. Camilleri picture John J. Camilleri · Feb 13, 2015 · Viewed 19k times · Source

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.

Answer

Kangcor picture Kangcor · Feb 13, 2015

See this solution in Stack Overflow

The problem is relative to the path where pm2 is watching, and if it is relative to the execution file or the actual root path of the project.