Using nodemon’s --ignore Option to Prevent Unnecessary Restarts
Learn how to use nodemon’s ignore feature to prevent restarts on test, log, or other files, with a concrete nodemon.json example, verification steps, and common pitfalls to avoid.
05 Mar 2026, 10:23 UTC

Quick answer: stop nodemon from restarting when you edit test or log files
Add an ignore array to your nodemon.json (or pass --ignore on the command line) with glob patterns that match the files you want nodemon to watch but not trigger a restart. When a matching file changes, nodemon continues running the existing process.
Worked configuration
Assume a Node.js project with the following layout:
my-project/
├─ src/
│ ├─ index.js
│ └─ utils.js
├─ tests/
│ ├─ unit.test.js
│ └─ integration.test.js
├─ logs/
│ ├─ app.log
│ └─ error.log
├─ package.json
└─ nodemon.json
You want nodemon to restart when src/**/*.js changes, but ignore changes to test files and log files. Create or edit nodemon.json in the project root:
{
"watch": ["src"],
"ext": "js",
"ignore": ["tests/**/*.js", "logs/**/*"],
"exec": "node src/index.js"
}
Explanation:
watchtells nodemon which directories to monitor (here onlysrc).extlimits monitoring to files with the.jsextension.ignoresupplies patterns that are subtracted from the watch set. Any file matchingtests/**/*.jsorlogs/**/*will not cause a restart.execis the command nodemon runs to start your application.
How to verify the ignore works
- Open a terminal in
my-projectand run nodemon:
nodemon
You should see startup output similar to:
[nodemon] 2.0.15
[nodemon] to restart at any time, enter `rs`
[nodemon] watching: src/*
[nodemon] ignoring: tests/**/*.js, logs/**/*
[nodemon] starting `node src/index.js`
The line beginning with Ignoring: (or ignoring: in newer versions) confirms the patterns were parsed.
- While nodemon is running, edit a file that should be ignored, e.g.:
echo "test" >> logs/app.log
Check the terminal: nodemon should not print a restart message. The process continues unchanged.
- Now edit a watched file, for example:
echo "console.log('changed');" >> src/utils.js
You should see a restart line:
[nodemon] restarting due to changes...
[nodemon] starting `node src/index.js`
This contrast demonstrates that the ignore patterns are working.
Limits and common pitfalls
1. Ignore does not prevent loading
The ignore filter only affects the restart trigger. Nodemon still loads ignored files at startup if they are required by your application. If a test file contains side‑effects (e.g., it starts a server when required), those side‑effects will still run.
2. Pattern syntax matters
- Do not add a leading slash unless you intend to match from the project root;
/tests/**/*.jswill match nothing on Windows and may match incorrectly on Unix. - Escape special glob characters only when you need a literal match; otherwise, let nodemon interpret
*,?, and[]as usual. - Placing
ignoreinside theexecobject or any nested field will be ignored; it must be a top‑level property.
3. Performance considerations
Each ignore pattern adds a filesystem scan step. Very deep or numerous patterns (e.g., **/node_modules/**/* combined with many custom ignores) can increase the number of inotify watches consumed on Linux. If you hit the fs.inotify.max_user_watches limit, nodemon may fail to start with an error like Error: watch ENOSPC. Mitigate by consolidating patterns or moving ignored directories outside the watched tree.
4. Case‑sensitivity on different OS
Glob matching respects the filesystem’s case‑sensitivity. A pattern like Logs/*.log will not match logs/error.log on a case‑sensitive Linux system but will on macOS (default) or Windows. Use lowercase patterns or enable the ignoreCase flag if your nodemon version supports it.
Practical checklist
- Add
ignoretonodemon.jsonwith the exact patterns you need. - Watch for the
Ignoring:line in nodemon’s startup log. - Test by editing an ignored file and confirming no restart occurs.
- Test by editing a watched file and confirming a restart occurs.
- Monitor system watch usage if you see
ENOSPCerrors (cat /proc/sys/fs/inotify/max_user_watcheson Linux).
By correctly configuring nodemon’s ignore option you can keep your development server stable while still gaining the benefits of automatic restarts for the source files that matter.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.