Using Nodemon's --ignore Flag to Stop Needless Restarts in a Node.js Dev Loop
Stop Nodemon from restarting on log files, coverage output, and other noise by configuring --ignore globs correctly — including pattern order, config-file setup, and a two-minute verification test.
14 Sept 2025, 19:00 UTC

The problem: restarts triggered by files your app never reads
Nodemon watches your project and restarts the Node.js process whenever a file changes. By default it watches broadly, so writes to log files, test fixtures, coverage output, or generated artifacts all bounce your server. The fix is the --ignore flag: you hand Nodemon one or more glob patterns (wildcard path expressions like logs/**) and matching files no longer trigger restarts.
The useful takeaway: ignore rules are cheap to add, but pattern order and version behavior matter. This guide covers the supported configuration paths, a concrete verification you can run in a scratch project, and the failure modes to watch for.
Prerequisites
- Node.js and npm installed (any currently supported LTS release is fine).
- Nodemon 1.0 or newer. The
--ignoreflag does not exist in pre-1.0 releases. Check withnpx nodemon --version. - A project where you can run Nodemon from a terminal, either installed locally (
npm install --save-dev nodemon) or globally.
Confirm your version supports the flag
Run this in your project directory (no special permissions needed):
npx nodemon --help | grep -i ignoreYou should see the --ignore option listed in the usage text. If nothing appears, upgrade Nodemon before continuing.
Three ways to declare ignore patterns
1. Command-line flag
Pass one or more glob patterns. Repeat the flag for multiple patterns rather than relying on comma separation, which is easier to read and less shell-sensitive:
npx nodemon --ignore 'logs/**' --ignore 'coverage/**' server.jsQuote the patterns so your shell does not expand the wildcards before Nodemon sees them.
2. Environment variable
Set NODEMON_IGNORE when you want the rule to follow the shell session rather than the npm script. This is useful in shared scripts where individual developers want different exclusions.
3. Configuration file
For team-wide rules, put them in nodemon.json at the project root so they are version-controlled with the code:
{
"watch": ["src"],
"ext": "js,json",
"ignore": ["src/**/*.test.js", "logs/**", "tmp/**"]
}Pairing ignore with an explicit watch list narrows the watched set first and then excludes within it, which keeps the file-watcher small and startup fast.
Pattern order decides what wins
When multiple rules could match the same path, the first applicable declaration takes precedence. That means a broad early pattern can silently swallow a narrower exception you added later. Practical guidance:
- Order patterns from most specific to most general when you mix inclusions and exclusions.
- Avoid overlapping rules like
src/**andsrc/keep.jsunless you have tested which one fires. - If behavior surprises you, temporarily reduce to a single ignore rule and add rules back one at a time.
Verify the ignore actually works
Do not assume the glob matched. Run this scratch test (takes about two minutes):
- Create a test folder with
src/app.js(a trivialconsole.log('start')script) andlogs/debug.log. - Start Nodemon:
npx nodemon --ignore 'logs/**' src/app.js. - Append a line to
logs/debug.log. Expected result: no restart message in the Nodemon console. - Touch or edit
src/app.js. Expected result: Nodemon prints a restart line naming the changed file.
Nodemon also prints the directories and rules it is using at startup (more detail with --verbose). Read that output once per project to confirm your patterns resolved the way you intended.
Limitations and gotchas
- Legacy environments: scripts shared with Nodemon versions older than 1.0 must not depend on
--ignore; the flag will be rejected or silently ineffective. Pin a minimum version indevDependencies. - Very long ignore lists: dozens of patterns add parsing overhead at watch initialization. Prefer a tight
watchlist over an ever-growing ignore list. - Changes during a restart: if a file changes while the process is mid-restart, that change can be missed; save again or let the process settle before editing.
- Generated files inside watched source: if your app writes into
src/(build caches, uploaded files), ignoring those paths is often the entire fix for restart loops.
Recovery if restarts still fire
If files you ignored still trigger restarts: check for unquoted globs expanded by the shell, confirm no conflicting earlier pattern matched first, and restart Nodemon itself — ignore configuration is read at startup, not reloaded live. As a last resort, run with --verbose and compare the reported watch set against your expectations.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.