Fine‑Tuning Nodemon with the --delay Flag: Debounce Your Restarts
Learn how Nodemon’s --delay option lets you debounce restarts, cut CPU churn, and improve test pipelines. See a concrete example, trade‑offs, and how to verify the setting in your project.
03 Jun 2026, 10:51 UTC

The Problem: Too Many Restarts
In a typical Node.js project, a single keystroke can trigger a file write, which Nodemon immediately notices and restarts the process. When you’re editing many files in quick succession—think refactoring a large module or running a test suite that touches several files—this can lead to a cascade of restarts. The result is high CPU usage, memory churn, and a frustratingly slow feedback loop.
How the --delay Option Works
The --delay flag tells Nodemon to wait a configurable amount of time after the last detected file change before it actually restarts the process. Internally Nodemon sets a timer each time a change event is fired. If another change occurs before the timer expires, the timer is reset. Only when the timer completes does Nodemon kill the old process and launch a new one.
Typical values range from 200 ms for quick debounces to 2000 ms for very noisy environments. The flag accepts a millisecond integer or a string with a time unit (e.g., 500ms, 1s).
Practical Use Cases
- Large Codebases: When a change touches many files, a short delay prevents a flood of restarts.
- Hot‑Module Replacement: Some build tools emit multiple rapid writes; a delay ensures the module is fully written before Nodemon restarts.
- Test Pipelines: In CI, a test runner may trigger file changes via coverage instrumentation; debouncing avoids restarting the test harness multiple times.
Example: Debouncing a Hot‑Reloading Express App
Suppose you have an Express application that uses Nodemon to watch src/**/*.js. You want to prevent the server from restarting on every keystroke during a refactor.
# Run with a 500 ms debounce
nodemon --delay 500 --watch src --ext js,ts app.js
When you edit src/controllers/user.js and src/models/user.js within 200 ms of each other, Nodemon will wait 500 ms after the last event before restarting. The console will show a single Restarting message instead of two.
Trade‑offs & Limitations
- Feedback Latency: A longer delay means the developer sees the result of changes later. In a fast‑iterating workflow, a 2000 ms delay can feel sluggish.
- Hiding Build Failures: If your build emits errors after the initial file write, a long delay might postpone the error until after the restart, making debugging harder.
- Not a Replacement for Watch Granularity:
--delayonly debounces; you still need--watchand--extto target specific files.
How to Verify the Delay Works
- Enable Verbose Logging
This prints timestamps and state changes to the console.nodemon --delay 500 --verbose app.js - Generate Rapid File Changes
Observe that Nodemon logs a singlefor i in {1..10}; do echo "// $i" >> src/temp.js; sleep 0.1; doneRestartingafter roughly 500 ms. - Measure CPU Usage
Use
topor a lightweight profiler while editing files in a loop. Compare the CPU spike with and without--delay 500. The spike should be noticeably lower when the delay is active.
Actionable Takeaway
If you’re experiencing noisy restarts or high CPU usage during development, add a --delay to your Nodemon command. Start with a moderate value (e.g., 500 ms), observe the effect, and adjust based on your workflow. Remember that the delay is a debounce, not a filter; combine it with --watch and --ext to fine‑tune which files trigger restarts.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.