Using nodemon.json to Control File‑Watch Triggers in Node.js Development
Learn how a nodemon.json file lets you define exact watch paths, ignore build artifacts, and set a debounce delay to prevent unnecessary restarts during Node.js development.
02 Dec 2025, 08:53 UTC

Why a Declarative nodemon.json Helps
Instead of remembering a long list of CLI flags, a nodemon.json file in the project root lets every team member use the same watch rules. This eliminates accidental restarts caused by changes in generated files or test suites.
Example Configuration
Create a file named nodemon.json at the root of your Node.js project with the following content:
{
"watch": ["src"],
"ignore": ["src/**/*.spec.js", "dist/*", "logs/*"],
"ext": "js,json",
"delay": "1.5"
}
What Each Property Does
watch: Limits monitoring to thesrcdirectory. Changes outside this folder are ignored unless added to the array.ignore: Uses glob patterns to suppress restarts. In the example, test files (.spec.js) and the build output (dist/) do not trigger a restart.ext: Restricts triggers to JavaScript and JSON files, preventing restarts when editing markdown or configuration files.delay: Sets a debounce timer in seconds. A value of1.5waits 1.5 seconds after the last change before restarting, which reduces duplicate events from editors that perform atomic saves.
Running nodemon with the Configuration
From the project root, execute:
# If nodemon is installed globally
nodemon server.js
# If nodemon is a devDependency (recommended)
npx nodemon server.js
Where to run: In a terminal with access to the project directory. Permissions: No special rights are needed beyond the ability to start a Node.js process. Risk: If the watch path does not exist, nodemon may fall back to watching the current directory, which could re‑introduce unwanted restarts. Verify the path exists before starting.
Limits and Common Mistakes
Process‑Level Restart
Nodemon restarts by killing the entire Node.js process and spawning a new one. All in‑memory state—such as cached data, active WebSocket connections, or global variables—is lost on each restart. It is not a hot‑module‑replacement tool.
Filesystem Event Reliance
Nodemon depends on the OS’s file‑watch API (e.g., inotify on Linux). In environments like Docker containers with bind mounts or network file systems, events may be delayed, missed, or duplicated. If you notice missing restarts, you can enable polling by adding "legacyWatch": true to nodemon.json, though this increases CPU usage.
Over‑Broad or Over‑Narrow Ignore Patterns
An ignore pattern that is too wide (e.g., *") will silence needed restarts, while a pattern that is too narrow (e.g., omitting node_modules) can cause thrash when dependencies are updated. Test your patterns by modifying a file that should be ignored and confirming no restart occurs, then editing a source file and verifying a restart.
Verifying the Configuration Works
- List watched directories: Run
nodemon --verbose server.js. The startup output shows each directory nodemon is monitoring. - Test ignore logic: Edit a file inside
dist/(or any ignored path). The terminal should display no restart message. - Test trigger logic: Edit a file under
src/. You should see a line like[nodemon] restarting due to changes...and the existing process exit with code 0 before the new process starts.
Practical check: After making a change, note the timestamp of the restart message; if the delay is set to 1.5 seconds, the restart should occur roughly that interval after the last save.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.