fs.watch is unstable and not consistent and sometimes reports events twice. I tried other packages out there but still the same thing. I tried the ‘chokidar’ package not to get the double logs, but it doesn’t report all the events if they happen extremely fast, for example doing a thousand writes to a file.
Can someone explain what is happening behind the scenes with C++ APIs and OS while calling the watch method in node.js?
import { log } from "console";
import { watch } from "fs/promises";
(async () => {
const watcher = watch("./somefile.txt");
for await (const event of watcher) {
log(event);
}
})();