Configuring Nodemon Watch Paths for Efficient Node.js Development
Learn to restrict Nodemon's file watching to only the source directories and extensions that matter, using a concrete nodemon.json example, verification steps, and a checklist of common pitfalls.
12 Sept 2026, 05:33 UTC

Why watch paths matter
Every time you save a file during development you want the Node process to restart automatically. Without a focused watch configuration Nodemon monitors the entire project tree, which can hit OS limits, waste CPU, and restart on irrelevant changes (e.g., generated assets, log files). The practical engineering decision is to restrict watching to the source directories and file extensions that actually affect runtime behavior.
How Nodemon watches files
Nodemon uses the operating system’s native file‑system event APIs (inotify on Linux, kqueue on macOS, ReadDirectoryChangesW on Windows). When an event fires for a path that matches the configured watch patterns and ext extensions, Nodemon spawns the command defined in exec (or the script you passed on the CLI). The process is a child of the Nodemon supervisor, so stdout/stderr stay attached to your terminal.
Worked configuration example
Create a nodemon.json at the repository root. The following configuration watches only the src directory for .js and .json files, ignores the dist build output, and runs the compiled entry point.
{
"watch": ["src"],
"ext": "js,json",
"ignore": ["dist/**", "node_modules/**"],
"exec": "node src/index.js",
"delay": 250
}Key fields:
- watch – array of directories or glob patterns to monitor.
- ext – comma‑separated list of file extensions that trigger a restart.
- ignore – patterns that suppress events; useful for build artefacts and dependency folders.
- exec – the exact command Nodemon will spawn on each restart.
- delay – debounce in milliseconds (here 250 ms) to coalesce rapid saves.
Verifying the configuration
Run the following steps in a terminal with a non‑root user (avoid sudo to prevent permission‑related security exposure).
- Install Nodemon locally (recommended for version pinning):
npm install --save-dev nodemon - Start the supervisor using the local binary:
npx nodemon - Confirm watched files – Nodemon prints a line such as
[nodemon] watching 124 files. The count should reflect onlysrc/**/*.jsandsrc/**/*.json. - Trigger a restart – edit
src/index.js(add a comment) and save. You should see:[nodemon] restarting due to changes... [nodemon] starting `node src/index.js`
| Step | Command | Expected output |
|---|---|---|
| Install | npm i -D nodemon | Package added to devDependencies |
| Start | npx nodemon | [nodemon] watching X files |
| Edit | Edit src/index.js | [nodemon] restarting… |
Limits and common mistakes
OS watch‑descriptor ceiling
On Linux the default fs.inotify.max_user_watches is 8192. A large monorepo with many directories can exceed this, causing Nodemon to fall back to polling or miss events. Mitigation: increase the kernel limit (sysctl -w fs.inotify.max_user_watches=524288) or narrow watch to a few top‑level folders.
High CPU from rapid restarts
If developers save many files in quick succession (e.g., auto‑format on save), Nodemon may spawn a new Node process every few milliseconds. The delay (debounce) option absorbs bursts; 150‑300 ms works for most editors.
Stale configuration after editing nodemon.json
Nodemon does not reload its own config automatically. After changing nodemon.json you must stop the process (Ctrl+C) and rerun npx nodemon. Forgetting this is the most frequent cause of “my ignore pattern isn’t working”.
Over‑broad ignore patterns
An ignore entry like **/*.js would suppress all JavaScript changes, leaving the server running outdated code. Test by temporarily removing ignore and confirming a restart fires, then re‑add precise patterns.
Node version compatibility
Nodemon 3.x requires Node ≥ 14 for stable file‑watching on Windows. On Node 12 or earlier you may see ENOSPC or missed events. Pin a compatible Nodemon version (npm i -D nodemon@2) if you cannot upgrade Node.
Practical checklist before committing
- Run
npx nodemon --versionand verify ≥ 3.0 (or 2.x for Node 12). - Confirm
nodemon.jsonis tracked in version control. - Execute
npx nodemon, edit a watched file, and observe a clean restart. - Check the “watching X files” line matches the expected count (roughly
find src -type f \( -name "*.js" -o -name "*.json" \) | wc -l). - Ensure no
sudoor elevated privileges are used.
Following this focused watch‑path strategy keeps restart latency low, avoids OS resource exhaustion, and eliminates the “why didn’t it restart?” debugging cycle.