How do you configure pm2 ignore_watch for multiple directories?

Viewed 128

I am running PM2 on windows 10 and have the following as my ecosystem.config.json file use to start the process.

module.exports = {
  apps : [{
    name        : "myApp",
    script      : "./server.js",
    watch       : true,
    watch_delay: 5000,
    ignore_watch: ['node_modules', 'tracking'], 
    env: {
      "NODE_ENV": "production",
    }
  }]
}

Whenever I update something in the tracking directory is causes a restart. If I move the file location to node_modules and remove tracking from the ignore_watch then it works. I have tried several other paths but anything other than node_modules does NOT seem to work with PM2.

Is the formatting incorrect or am I just missing something or is there a known issue in windows?

1 Answers

PM2 watch and unwatch folder and transpile with babel-node

I was looking for a simple solution for the development server!

Problem: When uploading files to the development server 'express-fileupload' PM2 detects a change in the folders and restarts the process.

I clarify this operation is fine because we had PM2 configured to monitor the entire project!

"ecosystem.config.js" is the configuration; it is simple. You can expand it with the official documentation of PM2. I leave it at the end! How do we fix it, to prevent restarting the process each time we upload a file?

Create the configuration file in the root folder:

ecosystem.config.js

module.exports = {
    apps: [
        {
            name: "DEH",
            script: "./server/index.js",
            interpreter: "./node_modules/@babel/node/bin/babel-node.js",
            interpreter_args: "./node_modules/@babel/node/bin/babel-node",

            watch: ["server"],
            watch_delay: 1000,
            ignore_watch: [
                "node_modules",
                "./server/src/files",
                "./server/src/pdf",
            ],
            watch_options: {
                followSymlinks: false,
            },
        },
    ],
};

To run it:

pm2 start ecosystem.config.js

Note that ignore_watch has an array with elements that will not be checked.

The interpreter points to the folder where it was installed locally: if you don't specify it you will have to install babel-node globally (I don't recommend it)

Related