Streamlining Node.js Development with Nodemon’s Ignore Patterns
Use Nodemon’s ignore patterns to exclude directories like dist/ and logs/ from triggering restarts. This guide shows how to set up nodemon.json, verify with --verbose, and troubleshoot common pitfalls.
23 Jul 2025, 04:47 UTC

Desired Outcome
Use Nodemon’s ignore feature to exclude specific directories or file types from triggering restarts, keeping the development loop fast and preventing unwanted reloads from generated files.
Prerequisites
- Node.js 18+ (any LTS version works)
- npm or yarn installed
- Basic knowledge of npm scripts and JSON configuration
Setup – Install Nodemon Locally
npm install --save-dev nodemon
Keep Nodemon in devDependencies so it isn’t bundled in production builds.
Centralizing Ignore Patterns with nodemon.json
Creating a nodemon.json file in the project root keeps ignore rules maintainable and removes the need to pass --ignore on the command line every time.
{
"watch": ["src"],
"ext": "js,json",
"ignore": [
"dist/**",
"logs/**",
"*.md"
],
"delay": "250"
}
Explanation of fields:
watch– directories Nodemon monitors.ext– file extensions that trigger a restart.ignore– glob patterns that exclude files from the watch list.delay– milliseconds to wait after the last file change before restarting.
Running Nodemon with Verbose Logging
npx nodemon --verbose
The --verbose flag prints every file Nodemon checks and shows which ones are ignored, helping verify the patterns.
Verification Checklist
Start Nodemon with
--verbose. Observe the log lines that includeIgnoredfor files indist/andlogs/.Modify a file inside
src/(e.g.,src/app.js) and confirm Nodemon restarts the process.Run a script that writes a log entry to
dist/server.logduring startup. Nodemon should not restart after this write.Temporarily delete the
dist/**entry fromignoreand repeat the test to see a restart occur, proving the rule’s effect.
Troubleshooting Common Issues
- Pattern Too Broad: If you notice critical source files aren’t triggering restarts, narrow the ignore pattern. Avoid using wildcards that match
src/**unintentionally. - File System Watching Limits: On Linux, the default
maxUserWatchesmay be too low for large projects. Increase it withecho fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p. - Docker Development: When mounting host directories into a container, Nodemon may miss changes. Use
--legacy-watchor addvolumes-fromwith--mount type=bind,source=./src,target=/app/srcto ensure file events propagate.
Recovery – Re‑Enabling Restarts
To undo the ignore effect without editing the file, run:
npx nodemon --ignore ''
Or reset the nodemon.json to its original state and restart Nodemon.
Practical Example – Excluding Build Artifacts
Suppose you compile TypeScript to dist/. A build step writes many new files each compile, which would otherwise flood Nodemon with restart events. By adding "dist/**" to ignore, only source changes trigger reloads, keeping the dev server responsive.
| Pattern | Effect |
|---|---|
dist/** | All files in dist/ are ignored. |
*.md | All Markdown files in any watched directory are ignored. |
logs/** | All log files under logs/ are excluded. |
Conclusion
By centralizing ignore patterns in nodemon.json and verifying with verbose logs, you can keep your Node.js development workflow lean. This approach prevents unnecessary restarts, avoids infinite reload loops from generated files, and keeps your project maintainable as it grows.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.