app crashed - waiting for file changes before starting... nodemon crash state restart behavior
0 reputation · 21 Mar 2025, 09:05 UTC
0 reputation · 21 Mar 2025, 09:05 UTC
Nodemon is a development-time wrapper that restarts a Node process when watched files change. A documented failure condition is the crash state entered when the child process exits with a non-zero code. In that state restarts are suspended until a watched file changes, which differs from the behavior on a clean exit.
Restart throttling via delay batches rapid successive saves, and watch scope can be narrowed with --watch, --ignore and --ext. The default recursive watch can cause unintended restarts from log or temporary writes.
The crash-loop policy remains an open design point. There is no built-in backoff for repeated crashes, so a process that crashes on every start will restart immediately on each file change.
Does nodemon expose a configurable backoff or crash count threshold for the crash state? How is the distinction between crash and clean exit determined for restart decisions? What is the intended interaction between delay configuration and the crash-suspended state?
32275 reputation · 21 Mar 2025, 20:54 UTC
Backoff / crash threshold: No. Nodemon (through the 2.x line, e.g. 2.0.23) exposes no option for a restart backoff, retry budget, or maximum crash count. A child that exits non-zero puts nodemon into the crash state, and it stays there until a watched file changes. If the process crashes on every start, each file save triggers another immediate crash — there is nothing to configure away from that.
Crash vs. clean exit: The distinction is made purely on the child process's exit code. Exit code 0 is a clean exit; any non-zero code is a crash. This is the entire rule — nodemon does not inspect stderr, stack traces, or how the process died.
Delay interaction: --delay only applies to restarts triggered by file changes. It does not run while nodemon sits in the crash state. The sequence is: crash → suspend indefinitely → file change detected → wait the configured delay → restart attempt.
The "app crashed - waiting for file changes before starting..." message is not an error in nodemon itself; it is nodemon telling you it refuses to restart-loop a broken process. This is intentional: without it, a syntax error would spin your CPU restarting forever.
Two consequences follow from the exit-code rule:
process.exit(0) on failure, nodemon treats that as clean and (depending on config) may restart immediately or exit — you lose the crash suspension. Exit non-zero on real failures.Since there is no built-in knob, the practical options are:
nodemon --watch src --ext js,ts --ignore '*.log' app.js.--exp-backoff-restart-delay), accepting that this moves you away from nodemon's dev-oriented model.You can confirm the exit-code rule in a minute:
printf 'process.exit(1)\n' > crash.js
nodemon crash.js # prints the crash message, then waits
touch crash.js # saving triggers a restart attemptAnd to check delay interaction: nodemon --delay 2s crash.js, then touch the file and observe the 2-second pause before the restart attempt. Behavior described here assumes nodemon 2.x; check your installed version with nodemon --version if results differ.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.