Search code examples
javascriptnode.jspackage.jsonnodemon

How to ignore with nodemon everything except a folder and an specific file?


I have this folder structure

.
├── admin/
│   └── ...
└── services/
    ├── user/
    │   ├── main.js
    │   └── model.js
    └── post/
        ├── main.js
        └── model.js

And this script in package.json

  "scripts": {
    "admin": "nodemon src/admin/ --exec babel-node",
  },

I want to restart the process only when something inside admin/ changes or when a file called model.js outside of the admin folder changes.

How I can achieve this?


Solution

  • You can create a nodemon.json file in the root of your project and then add the folders/files to watch in the watch property. nodemon.json will be used as the config for nodemon. You can also ignore files/folders as well.

    {
      "ignore": [
        "services/*.js",
        "services/**/*.js"
      ],
      "watch": [
        "admin/*",
        "model.js"
      ]
    }