Other nodejs fs.watch kqueue - I need the name of the modified file

Nodejs fs.watch (https://nodejs.org/api/fs.html#caveats) is implemented using kqueue (https://www.freebsd.org/cgi/man.cgi?query=kqueue&sektion=2) for FreeBSD.

Here is a small piece of code that uses fs.watch taken from the above nodejs page (slightly modified to watch a subdirectory ./src):
Code:
import { watch } from 'node:fs';

watch('./src', (eventType, filename) => {
  console.log(`event type is: ${eventType}`);
  if (filename) {
    console.log(`filename provided: ${filename}`);
  } else {
    console.log('filename not provided');
  }
});
I save the above code in testwatch.mjs in the parent directory and run from a terminal:
node testwatch.mjs
and leave it running.

In another terminal, I first cd to src and then use vim to edit a file called test.txt and enter "this is a test" and save the file. I see the following in the first terminal:
Code:
node testwatch.mjs
event type is: rename
filename not provided
event type is: rename
filename not provided
event type is: rename
filename not provided
^C

Here is my question. Is there a way to get the filename that was modified?

Having the filename would allow webpack-dev-server to rebuild a Reactjs application (client-side JavaScript) created using create-react-app which would automatically rerender the changes on the browser using the HotModuleReplacement plugin when one is using the development mode in create-react-app. Webpack-dev-server uses fs.watch to watch for file modifications.
 
Providing filename argument in the callback is only supported on Linux, macOS, Windows, and AIX. Even on supported platforms, filename is not always guaranteed to be provided.
 
Wondering what would it take for FreeBSD to provide the filename? I guess we need to tinker with the source code of kqueue and kevent?
 
Back
Top