Search code examples
javascriptnode.jspm2

Watch files outside the current directory using pm2


Is there a way to detect changes outside the current directory using pm2? For example on /home/sprguillen/workspace/node I have an index.js which is the script to be ran by pm2. Now I have a configuration file outside it located on /home/sprguillen/workspace/config. I have my own reasons not to put it inside the node directory such as the possibility of having different node applications to access the same configuration file. Is this possible using pm2 that any changes found on say /home/sprguillen/workspace/config will be included by the watch?


Solution

  • According to the doc you can configure watch option in the ecosystem.config.js to monitor multiple paths. So you can try something like this:

    module.exports = {
      apps : [{
        name: "app",
        script: "./index.js",
        watch: [
            ".",
            "../config",
        ],
      }]
    }
    

    And run your app from the same directory as ecosystem.config.js: pm2 start