Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Nodemon was sometimes failing to notice when files changed. After some debugging, I discovered that it was unnecessarily trying to open a vast number of files that exceeded the ulimit maximum. Specifically, the following issues have been fixed:
fs.watch
was previously watching files matching .nodemonignore regexes. Listing a file in .nodemonignore only prevented nodemon from restarting, but not from opening the file viafs.watch
. This created a potentially enormous number of unnecessarily open files from directories like .git and node_modules. This commit fixes that behavior by filtering out the ignored files before handing them tofs.watch
.fs.watch
was previously opening each file each time nodemon restarted, without closing the previously open files. That quickly added up to an enormous number of open files. This commit fixes that behavior by keeping an array ofwatched
files, and only requestingfs.watch
for files not already in that array.catch
EMFILE errors. A newconsole.error
message has been added to identify when too many files are open for watching. After the first two fixes, such situations should be rare, but in larger projects it's easy to trigger by omitting /.git/ and /node_modules/ from .nodemonignore. Prior to the above two fixes, I was seeing hundreds of caught EMFILE errors each time nodemon restarted.