144

I would like to exclude some specific files from monitoring of NodeMon. How can I do this?

My existing configuration:

nodemon: {
      all: {
        script: 'app.js',
        options: {
          watchedExtensions: ['js']
        }
      }
1
  • I presume I should edit the .nodemon-ignore file in the root of the application...
    – Ben Aston
    Jun 9, 2014 at 12:13

4 Answers 4

262

In order to make NodeMon ignore a bunch of files from monitoring, you can start it as

nodemon --ignore PATTERN [--ignore PATTERN2]

where PATTERN is the name of a specific file, directory, or wildcard pattern. Make sure that if you use a wildcard, it is escaped.

For example

nodemon --ignore 'lib/*.js' --ignore README

Alternatively, if you want to configure that behaviour instead, try creating a nodemon.json file in your current working directory, or your home directory. You can configure ignoring some files by adding something like the following to this config file:

{   
    "ignore": ["lib/*.js", "README"] 
}

Refer the README file at https://github.com/remy/nodemon for more details.

5
  • 2
    didnt' work for me, I needed to use path without simple-quotes: nodemon --ignore public/ build.js This is maybe due to french keyboard layout in windows...
    – TOPKAT
    Apr 22, 2018 at 16:55
  • not work for me to. but i use npx or npm script.mybbe that the reason, Jun 15, 2020 at 12:00
  • On Windows quoting with single quotes does not work. Double quotes do work. Aug 7, 2020 at 10:05
  • @LorenzMeyer, seemed to work fine with single quotes on powershell, at least for the first variant.
    – Gates
    Jan 20, 2021 at 15:20
  • 1
    This works for me in my package.json so it only restarts if I make changes to my server. "scripts": { "start": "nodemon --ignore public/*" } Mar 16, 2021 at 14:23
59

You can add nodemon configuration within package.json file For example:

{
  "name": "nlabel",
  "version": "0.0.1",
   // other regular stuff


  "nodemonConfig": {
    "ignore": ["public/data/*.json", "public/javascripts/*.js"]
  },


  "author": "@sziraqui",
  "license": "GPL-3.0"
}

The key must be "nodemonConfig". Ignore rules can be specified as array of globs or complete filenames

More info: https://github.com/remy/nodemon#packagejson

3
  • 2
    Couldn't get any version of --ignore to work but this did. Clean solution as well. Nov 21, 2019 at 10:39
  • Can I get info on terminal which files/folders are excluded in nodemon? I just see Nico's answer, should help
    – Timo
    May 15, 2021 at 18:36
  • @Timo Couldn't find any nodemon config for your use case. You can use ls 'your exlusions' && nodemon app.js (not cross platform). If you are willing to write code for it, you can listen to nodemon 'start' or 'restart' event and print excluded files by reading nodemon config and expanding glob patterns in "ignore" array.
    – sziraqui
    May 18, 2021 at 19:38
10

For me (Mac and nodemon 1.18.3), the only way to ignore entire directories is to run e.g.

nodemon --ignore "**/old/**"

with the double quote and **. The config file won't work.

I have set up an alias like this:

alias nm='nodemon server.js -i "**/old/**" -i "**/img/**"'

Check what files are monitored by running

DEBUG=nodemon:watch nodemon server.js -i "**/old/**" -i "**/img/**"

-i is an alternative to --ignore. Check out the available parameters with nodemon --help

3

If like me nothing is working for you, follow my instructions.

Do not use the '' around your path('login.json' is wrong for example)

And CTRL + S won't suffice, you need to close the terminal and use the command npm run devStart AGAIN if you want your changes to take place in your packages.json

  "scripts": {
    "devStart": "nodemon server.js --ignore login.json"
  },

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.