I have a Node.js server I am developing and I'm using nodemon to have the server restarted when the source code changes.
This server has a dependency on another module, which I am also developing, so it would be nice if changes to that module also restarted the server.
Best attempt yet (Thanks, bitstrider!)
I made a repo to reproduce this problem with minimal code if anyone wants to check it out: https://github.com/shawninder/nodemon-troubles
The highlights are in nodemon.json
:
{
"ignoreRoot": [
".git",
".nyc_output",
".sass-cache",
"bower-components",
"coverage"
],
"ignore": [
"node_modules/!(is-node)",
"node_modules/is-node/node_modules"
]
}
ignoreRoot
is the same as the defaults, but without node_modules
.ignore
is where I'm trying to tell it to ignore node_modules, but not is-node
.This almost works (editing is-node restarts the server) but it's watching all the node modules, not only is-node.
How can I tell nodemon to ignore all node modules except for one?
Details
Explaining the problem
Nodemon takes the ignores and combines them into one big regular expression before passing this along to chokidar. It's a custom parsing algorithm based on regular expressions and supports neither glob negation nor regular expression syntax. For example, the example above produces the following regular expression:
/\.git|\.nyc_output|\.sass\-cache|bower\-components|coverage|node_modules\/!\(is\-node\)\/.*.*\/.*|node_modules\/is\-node\/node_modules\/.*.*\/.*/
Notice the negation character !
end up as a literal !
in the resulting regular expression. Using negative look-ahead syntax also doesn't work because the control characters are transformed into literal characters.
Since nodemon
uses minimatch
for matching, you should be able to use negation with the symbol !
, according to the documentation.
So in your case, try:
{
"ignore" : "node_modules/!(my-watched-module)/**/*"
}
This should ignore all module files except those within my-watched-module
NOTE: The
ignore
rule here only targets files, not directories. This behavior makes sense in the context ofnodemon
because its watching for file changes.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With