59

In a Universal Javascript app, I would like nodemon to ignore client directory changes.

I have tried the following:

"devStart": "nodemon server/server.js --ignore 'client/*' --exec babel-node",
"devStart": "nodemon server/server.js --ignore 'client/' --exec babel-node",
"devStart": "nodemon server/server.js --ignore client/ --exec babel-node",
"devStart": "nodemon --ignore 'client/*' server/server.js --exec babel-node",
"devStart": "nodemon --ignore 'client/' server/server.js --exec babel-node",
"devStart": "nodemon --ignore client/ server/server.js --exec babel-node",

None of these work.

File structure:

+-server
+-client
+-package.json <------- where nodemon script is

However this is not working. Pretty sure it is a pattern issue.

Any ideas?

softcode
  • 4,358
  • 12
  • 41
  • 68

5 Answers5

99

You need to replace .. with ., or just reference client/ directly, also you will need to remove the asterisk:

"devStart": "nodemon --ignore ./client/ --exec babel-node src/server.js"

Or

"devStart": "nodemon --ignore client/ --exec babel-node src/server.js"

According to nodemon docs this is how to ignore a directory via command line:

nodemon --ignore lib/ --ignore tests/

Also note that nodemon will only restart the node process, if you change the npm script you will need to kill the process and re-run npm run devStart

turbopasi
  • 3,327
  • 2
  • 16
  • 43
hackerrdave
  • 6,486
  • 1
  • 25
  • 29
  • Edited my `package.json` is actually in the same directory as `client` and `src` – softcode Jan 28 '17 at 18:25
  • have updated the answer to remove the asterisk - nodemon docs say to follow this pattern: `nodemon --ignore lib/ --ignore tests/` – hackerrdave Jan 28 '17 at 18:34
  • I tried that also. Could it be the order of things? Should the directory nodemon is expected to run come after the ignore? – softcode Jan 28 '17 at 18:37
  • 1
    Ok got it. I was expecting the server reload to actually reload the devStart script. Turns out I had to kill the process and run `npm run devStart` again. If you can update your answer to reflect this I will accept it. @hackerrdave – softcode Jan 28 '17 at 18:56
  • "you will need to remove the asterisk" worked for me! Thank you. – natterstefan Aug 17 '19 at 09:08
  • 2
    I had to remove the quotes around `client/` – Cullub Jun 02 '20 at 23:00
  • 1
    REMOVE THE QUOTES works for me: `nodemon --ignore client src/server.js` – Tran Anh Minh Mar 01 '21 at 14:34
57

In the very likely circumstance that you're using nodemon in a configuration file, you can create a separate configuration entry for those files to be ignored. Bonus, a cleaner looking nodemon call, especially if files to ignore grows large.

For example, this package.json instructs nodemon to ignore directory test:

{
  "scripts": {
    "test": "jest",
    "start": "nodemon server.js"
  },
  "nodemonConfig": {
      "ignore": ["test/*"]
  }
}

Find the complete instructions for nodemon configuration file settings here.

As in the other answer, be sure to restart nodemon for the configuration changes to take effect.

Andrew Philips
  • 1,950
  • 18
  • 23
7

Create nodemon.json in your project root that looks something like this:

{
  "ignore": ["db.json"]
}

This is an alternative to using package.json as seen in Andrew Philips answer

See docs

danday74
  • 52,471
  • 49
  • 232
  • 283
4

just so you all know, i was using this pattern to exclude directories :

node_modules/**

but it led to using a LOT of watchers: nearly 500000 on one of my projects and now i use

node_modules/

which uses only 134 watchers.

Always monitor your work

Raphael PICCOLO
  • 2,095
  • 1
  • 12
  • 18
  • Any guidance on how you monitor these watchers? – dKen May 05 '23 at 06:40
  • For those who stumble across this, you can add `"verbose": true,` to your `nodemon.json` file and it'll show you the count of files being watched. – dKen May 05 '23 at 06:51
  • @dKen i used this to count inotify handles : https://github.com/fatso83/dotfiles/blob/master/utils/scripts/inotify-consumers – Raphael PICCOLO Jun 07 '23 at 20:22
0

Also you can use something like this to run nodemon only in a specific folder. This way you don't have to add multiple --ignore parameters.

{
  "scripts": {
    "devStart": "cd ./server/ && nodemon ./server.js"
  }
}
ozgrozer
  • 1,824
  • 1
  • 23
  • 35