Stop nodemon restart thrash with delay and ignore patterns
Tune nodemon's debounce delay and watch ignores so your Node.js dev server restarts only when it should.
26 Aug 2026, 19:56 UTC

Problem: every save restarts your server
You save a TypeScript file, and nodemon restarts your API. You save it again a moment later, and it restarts again. If your build tool writes output into a watched folder, nodemon can restart once for the source change and again for each generated file. The result is a flurry of restart messages, lost in-memory state, and slower feedback while you wait for the process to come back up.
The useful takeaway: nodemon's restart is not a single event you have to accept. It is a pipeline—file change, operating-system watcher, debounce timer, process restart—and you can tune each stage so restarts happen only for the files that matter.
Assumes a current nodemon release; the flag names referenced here have existed across multiple major versions.
How nodemon decides to restart
Nodemon watches files using native OS mechanisms where available: fsevents on macOS, inotify on Linux, and polling on Windows. When a watched file changes, nodemon does not restart immediately. It starts a debounce delay—a short window during which additional changes are collapsed into a single restart. The default is typically one second, adjustable with the --delay flag.
You control which files start that timer with --watch and --ignore. Without these, nodemon watches the current directory and subdirectories, which often includes build output, logs, and dependency caches.
Worked example: calm restarts in a TypeScript project
Imagine a project where tsc compiles src/ into dist/, and you run the app with nodemon. By default, nodemon watches both folders. Editing src/index.ts triggers a restart; the compiler writing dist/index.js triggers another.
Run this from your project directory in a terminal. No special permissions are required.
nodemon --delay 2000 --watch src --ignore dist -- node src/index.js
Placeholders: replace src with your source directory, dist with your generated output directory, and node src/index.js with your application entry point.
--delay 2000waits two seconds after the last change before restarting, so rapid saves collapse into one restart.--watch srclimits the watcher to source files, so changes indist/do not start the timer.--ignore distexplicitly excludes generated output as extra protection.- The double dash
--separates nodemon options from the command passed to Node.
Expected check: after saving a file in src/, the terminal should print a "restarting" message roughly within the delay window, and the Node process should come back with your changes. Saving only inside dist/ should produce no restart message.
Risk: if you ignore a directory that contains runtime configuration the app reads, nodemon will not restart when that configuration changes. You will need to restart manually or narrow the ignore pattern.
Choose a watcher strategy by operating system
Windows defaults to polling because native directory change notifications are less reliable there. Polling checks files on a timer, which can raise CPU usage on large projects. On network-mounted or cloud-synced folders, even macOS and Linux watchers may miss events.
| Situation | Suggested nodemon behavior |
|---|---|
| Local macOS or Linux project | Default native watcher; add --delay if saves are frequent |
| Windows local project | Default polling; consider --legacy-watch or explicit --watch paths to reduce CPU |
| Network drive or synced folder | Native events may not fire; test polling or explicitly list directories with --watch |
Verify the active watcher
Run nodemon --verbose in your project directory. It prints the watcher type and the paths nodemon is tracking. Confirm the mechanism matches your environment before tuning delays or ignores.
Limitation: delay trades speed for stability
A longer debounce means fewer restarts, but also a longer wait between saving and seeing the change. Two seconds is a practical starting point; reduce it if the lag feels distracting, increase it if your build tool generates many files per save. Ignoring output directories prevents restarts from generated files, but it also means nodemon will not notice if you manually edit a generated file and expect a restart.
Practical closing
Start with defaults. If you see repeated restarts after a single save, add --delay. If your build output lives inside the project folder, add --watch and --ignore for the source tree and generated tree respectively. Confirm with nodemon --verbose and a test save. The goal is fewer restarts, not no restarts: nodemon should restart when your code changes, and stay quiet when it does not.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.