nodemon icon indicating copy to clipboard operation
nodemon copied to clipboard

Nodemon API `restart` callback only returns one file even when multiple files change within delay window

Open sangafabrice opened this issue 1 month ago • 4 comments

  • Versions: [email protected], [email protected]
  • nodemon -v: 3.1.10
  • Operating system/terminal environment (powershell, gitshell, etc): Windows/gitshell
  • Using Docker? What image: no
  • Command you ran: N/A (Used Nodemon API)

Expected behaviour

The files array passed to the restart callback should include all files that were modified within the configured delay window. In the provided example below (steps to reproduce), three files are created simultaneously:

[
    'src\\script1.js',
    'src\\script3.js',
    'src\\script2.js'
]
  • The order of the array is not important.
  • What matters is that all relevant file paths are captured and passed to the callback.

Actual behaviour

Despite multiple files being created within the configured delay window, the files array passed to the restart callback contains only a single file—specifically, the last file modified.

In the provided example, the output is:

[ 'src\\script2.js' ]

This suggests that Nodemon is not aggregating all file changes during the delay period, but is instead reporting only the most recent one.

Steps to reproduce

  1. Initialise a basic project and set up the watcher:
npm init -y --init-type=module
npm i -D nodemon
mkdir src
touch index.js watch.js 
  1. Add the following code to watch.js:
/** @file: watch.js */
import nodemon from "nodemon";
import { relative } from "node:path";

nodemon({ 
    watch: "src",
    delay: 2_000
}).on(
    "restart",
    (files) => console.warn(files.map(file => relative(".", file)))
);
  1. Run the watcher and create multiple files simultaneously (src/script1.js, src/script2.js, and src/script3.js):
(node watch.js & (sleep 2 && touch src/script1.js && touch src/script3.js && touch src/script2.js && sleep 4)) > /dev/null

sangafabrice avatar Nov 05 '25 23:11 sangafabrice

This is how it's always worked - the last file to trigger the restart is what's passed in.

What you're after is a feature change. I can look at it, but I don't have a great deal of time available at the moment.

remy avatar Nov 06 '25 08:11 remy

Hi! I'd like to work on this issue and submit a PR. To confirm my understanding: Nodemon currently stores only the last modified file and passes it to the restart callback. Instead, you want an aggregated list of all files changed within the delay window. My plan:

Track all modified files in an array during the debounce/delay period Flush the full list to the restart callback Reset the list after each restart

Questions before I start: Are you okay with adding a new internal array to collect file paths? Should the new behavior be default, or behind an option such as aggregateFiles: true? Please assign this issue to me if possible.

Thanks!

KirtiGautam620 avatar Nov 15 '25 13:11 KirtiGautam620

@KirtiGautam620 Your understanding is correct.

I believe the implementation decision should be @remy's concern. But my humble opinion would be to make it available behind an option.

sangafabrice avatar Nov 16 '25 00:11 sangafabrice

This issue has been automatically marked as idle and stale because it hasn't had any recent activity. It will be automtically closed if no further activity occurs. If you think this is wrong, or the problem still persists, just pop a reply in the comments and @remy will (try!) to follow up. Thank you for contributing <3

github-actions[bot] avatar Nov 30 '25 00:11 github-actions[bot]