Expressjs pm2 ignore watch public/images folder

A simple explanation, from actual experience

create a json file in the root folder of the the expressjs application. It can have any name, but I used pm2-process.json for clarity

{
    "script": "bin/www",
    "watch": true,
    "ignore_watch": ["log"],
    "watch_options": {
        "followSymlinks": false
    },
    "name": "YOUR_PM2_PROCESS_NAME"
}

To start your pm2 service from terminal, in the root folder of the express application:

pm2 start pm2-process.json

That's it. Really simple. There are many other options but this is the bare functional minimum .

Fields explanation:

  • script - the script to run the express application
  • watch - a boolean flag to control if pm2 watches (or not) the folder
  • ignore_watch - if watch is on, then tell pm2 which folders to ignore watching (in other words, this is a watch monitor exclusion list)
  • name - the name of the pm2 process ('service'). Set it to your application name of choice.

The full documentation is here: http://pm2.keymetrics.io/docs/usage/application-declaration/#attributes-available

Note: I left the node_modules folder out of the ignore_watch array in the example above, because I want pm2 to restart the service after a git pull and npm i that causes a change in the node modules. However it easy to ignore node_modules or any other folder (e.g., temp, public, etc.) by editing the array values


PM2 has special flag --ignore-watch flag.

Try creating file process.json in the same directory where your app.js/index.js is and paste this:

{
  "watch": ["server", "client"],
  "ignore_watch" : ["node_modules", "public/images"],
  "watch_options": {
    "followSymlinks": false
  }
}

More on that topic: http://pm2.keymetrics.io/docs/usage/watch-and-restart/