node.jsnodemon

How to make the "nodemon" to watch only single file?


In my case the output file (FrontServerEntryPoint.js) is being built by the Webpack.

nodemon LocalDevelopmentBuild/FrontServerEntryPoint.js --environment local

I want nodemon watch only this file. I have no the unambiguous experimental results but I suspect that nodemon watches all .js file because think that all such files are related with entry point. If so, please teach me to make the nodemon watch only FrontServerEntryPoint.js, or suggest the alternative which can do it.


Solution

  • With some quick experiment, following nodemon config only watches a single file:

    {
        "restartable": "rs",
        "ignore": [
            ".git",
            "node_modules/**/node_modules"
        ],
        "verbose": true,
        "execMap": {
            "js": "node --harmony"
        },
        "events": {
            "restart": "osascript -e 'display notification \"App restarted due to:\n'$FILENAME'\" with title \"nodemon\"'"
        },
        "watch": [
            "multipart.js" // this is the only file which nodemon is watching and restarts the server
        ],
        "env": {
            "NODE_ENV": "development"
        },
        "ext": "js,json"
    }
    

    You can place this file in the root folder of your project.

    reference: https://github.com/remy/nodemon/blob/master/doc/sample-nodemon.md

    test on mac M1