nodemon ignore directory
Asked Answered
P

5

61

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?

Petronella answered 28/1, 2017 at 18:10 Comment(8)
I'd suggest store your nodemon configurations in nodemon.json file. would make it cleaner.Sharpfreeze
@Aᴍɪʀ Thanks for the tip. Any tips for the actual question?Petronella
pretty sure its just the path to client thats off - should be ./client/*, or client/*Burnham
can you try without the ' marks around and also use . instead of ..: './client/*' and also without *?Sharpfreeze
@Aᴍɪʀ edited package.json is actually in the same directory as server and clientPetronella
just to be clear, you are running it through npm run devStart, right? does it work if you write the exact same thing directly in command line?Sharpfreeze
@Aᴍɪʀ yes sir I amPetronella
The command nodemon server/server.js --ignore client/ --exec babel-node should work. I just tested it out. Make sure that you're ending nodemon after saving your package.json file.Ellis
B
102

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

Burnham answered 28/1, 2017 at 18:20 Comment(8)
Edited my package.json is actually in the same directory as client and srcPetronella
have updated the answer to remove the asterisk - nodemon docs say to follow this pattern: nodemon --ignore lib/ --ignore tests/Burnham
I tried that also. Could it be the order of things? Should the directory nodemon is expected to run come after the ignore?Petronella
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. @BurnhamPetronella
"you will need to remove the asterisk" worked for me! Thank you.Flaw
I had to remove the quotes around client/Parlando
REMOVE THE QUOTES works for me: nodemon --ignore client src/server.jsLampoon
You can ignore a set of directories by using asterisk (ie: --ignore 'foo-*/')Pazpaza
N
58

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.

Nosepiece answered 5/4, 2019 at 23:22 Comment(0)
F
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

Foothold answered 14/4, 2021 at 22:59 Comment(0)
S
5

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

Shannon answered 19/10, 2021 at 10:7 Comment(3)
Any guidance on how you monitor these watchers?Thracophrygian
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.Thracophrygian
@Thracophrygian i used this to count inotify handles : github.com/fatso83/dotfiles/blob/master/utils/scripts/…Shannon
H
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"
  }
}
Hare answered 19/12, 2020 at 16:19 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.