Using nodemon’s ignore feature to limit unnecessary restarts
Learn how to use nodemon’s ignore feature to prevent unnecessary restarts on logs, assets, or generated code, with configuration examples, verification steps, and failure‑mode analysis.
20 Nov 2025, 16:37 UTC

Requirements
During active development a Node.js server is often restarted whenever any file in the project changes. In many projects large volumes of logs, compiled assets, or generated code change frequently but do not affect the running application. Restarting on those changes wastes CPU and I/O, slows feedback loops, and can obscure real issues caused by source‑code modifications.
Smallest suitable design
nodemon already watches the file system and triggers a restart on any matched change. The built‑in ignore mechanism lets developers specify patterns that nodemon should skip when deciding whether to restart. The smallest design that satisfies the requirement is to add an ignore list either in a .nodemonignore file or inside nodemon.json. No additional tooling or process changes are needed.
Trust/data boundaries
Ignore patterns are interpreted relative to the project root where nodemon is started. If both .nodemonignore and nodemon.json contain an ignore key, nodemon merges the lists, giving priority to patterns defined in nodemon.json when the same glob appears in both files. This means the trust boundary is the project root: any pattern that walks outside that root (e.g., ../*) is ignored by nodemon and will not affect watching.
Operational checks
Start nodemon with debug output to verify the watch list:
# Run from the project root nodemon --debug src/index.jsLook for lines like
Watching:andIgnoring:to confirm that the patterns you added are being applied.Edit a file that should be ignored (e.g.,
logs/app.log) and observe that nodemon does not print a restart message.Edit a source file (e.g.,
src/index.js) and verify that nodemon restarts the process.
Failure modes
Overly broad globs (e.g.,
**/*) can unintentionally ignore source files, causing the server to run stale code.Patterns that are incorrectly scoped (e.g., using an absolute path) are treated as relative to the project root and may not match anything, leaving the unwanted files still watched.
Changing the ignore configuration itself does not trigger a restart; you must manually stop and start nodemon for the new rules to take effect.
Conditions that would change the design
The ignore‑based approach remains appropriate as long as:
- The set of files that should not cause a restart can be described with glob patterns relative to the project root.
- You are comfortable manually restarting nodemon after tweaking the ignore list.
- No other watch‑based tool (e.g., a Docker volume sync or a separate build watcher) relies on nodemon’s restart events for coordination.
If any of those conditions fail — for example, if you need to restart on changes inside a generated folder under certain circumstances, or if you are running nodemon inside a container where file‑system events are delayed — you might replace the simple ignore list with a custom nodemon script that uses the --signal flag or a separate watcher (like chokidar) to make more nuanced decisions.
Practical verification
Create a minimal test project:
mkdir nodemon-ignore-demo && cd nodemon-ignore-demo
npm init -y
npm install express nodemon
mkdir -p src logs
cat > src/index.js <<'EOF'
const express = require('express');
const app = express();
app.get('/', (req, res) => res.send('Hello'));
const PORT = process.env.PORT || 3000;
app.listen(PORT, () => console.log(`Listening on ${PORT}`));
EOF
Add a basic nodemon configuration that ignores the logs directory:
cat > nodemon.json <<'EOF'
{
"ignore": ["logs/**"]
}
EOF
Start nodemon with debug output:
nodemon --debug src/index.js
In another terminal, modify a log file:
echo "test" >> logs/app.log
You should see no restart message in the nodemon output. Then edit the source:
echo "console.log('changed');" >> src/index.js
Nodemon will print a restart line and the server will reload.
To confirm that the ignore list is being read correctly, look for a line similar to:
Ignoring: logs/**
If you remove the ignore entry from nodemon.json and restart nodemon, the same log edit will now trigger a restart, demonstrating that the setting is active.
Limitations and practical checks
Because ignore patterns are rooted at the project directory, you cannot use them to watch files outside that tree without symlinking or copying those files into the project. Additionally, nodemon does not re‑evaluate the ignore list on the fly; any change to .nodemonignore or nodemon.json requires a manual nodemon restart. The simplest way to validate that your ignore rules are working is to combine the debug flag (--debug) with deliberate file edits as shown above, or to inspect the nodemon process list via ps to see whether the main Node process has been replaced after a change.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.