Nodemon restarts inconsistently after file changes: chokidar default vs --legacy watcher behavior
0 reputation · 09 Dec 2020, 06:13 UTC
0 reputation · 09 Dec 2020, 06:13 UTC
I am configuring nodemon for a development workflow and need to understand one unresolved point before locking in our setup: since nodemon v1.0 switched its default file watcher from Node's native fs.watch to chokidar, restart timing and resource usage reportedly differ from the older implementation. The --legacy flag is documented as a way to force the previous fs.watch behavior.
My constraints: the team works across macOS, Windows, and Linux machines, plus Docker containers with mounted volumes, so watcher behavior may not be uniform. I also want to avoid depending on --legacy if it may be removed in a future major release. I have not yet observed a concrete failure; this is a design decision about which watcher to standardize on and how to verify it behaves correctly everywhere.
Specifically:
35275 reputation · 09 Dec 2020, 14:43 UTC
Standardize on the chokidar default watcher and tune its delay and polling options; reserve --legacy only for cases where you have confirmed missed changes that chokidar's fallback does not fix, since the flag may not survive future major releases.
--legacy forces the older Node fs.watch implementation.--delay interval (about 100 ms by default) before restarting, collapsing a burst of saves into one restart.fs.watch forwards events immediately, which can produce multiple restart notifications for a single edit.fs.watch events may never propagate, causing silent missed changes; chokidar detects watcher failure and falls back to polling, trading CPU for reliability.File.js and file.js as distinct paths, which can cause duplicate restarts unless paths are normalized.Restart timing differences come from chokidar's debounce delay versus fs.watch's immediate forwarding. Missed changes on shared volumes are more likely with fs.watch because the kernel does not reliably emit events for bind-mounted files; chokidar's polling fallback exists precisely to cover that gap.
DEBUG=nodemon* nodemon your-app.js # expect a line containing "watch: chokidar"
DEBUG=nodemon* nodemon --legacy your-app.js # expect a line containing "watch: legacy"nodemon --pollingInterval 500 your-app.jsnodemon --delay 150 your-app.jsOne caveat: polling raises CPU usage on large watch trees, so keep --pollingInterval conservative and use --ignore for directories like node_modules and build output. If inconsistent restarts persist after these settings, the missing diagnostic is the exact mount type (e.g., Docker Desktop gRPC FUSE vs. virtiofs vs. plain Linux bind mount), since that determines whether events can propagate at all.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.