fs.watch via Node 0.5.9 on Mac OSX

1.6k Views Asked by At

I'm running the following on Node v0.5.9:

var fs = require("fs");
fs.watch("/Users/username/testingFsWatcher/",function(event,file) {
  console.dir(arguments);
});

I then do:

  • cd /Users/username/testingFsWatcher/
  • >file1 --> { '0': 'rename', '1': null }
  • mkdir new_folder --> { '0': 'rename', '1': null }
  • >new_folder/file2 --> no event triggered/output
  • touch file1 --> no event triggered/output
  • rm file1 --> { '0': 'rename', '1': null }

Two things I noticed that seem incorrect: subdirectories (new_folder) are not watched and updates/modifications to watched files do not trigger a change event. Looking over the node code and tests it seems like these should be possible.

So, is it possible to get fs.watch to watch a directory and all of it's subdirectories? Is it at least possible to get an event from a file modification? Also, from what I can tell, fs.watch is backed by kqueue which is tied to an eventid (in OSX), is it possible to get that eventid?

Note: I'm specifically using fs.watch and not fs.watchFile because I need to watch an entire directory (preferably all of it's subdirectories too :).

Thanks for the help!

1

There are 1 best solutions below

0
On

This problem no longer appears in the latest Node release. However, there are several other remaining bugs in fs.watch, so you may want to hold off on using it until those are addressed: https://github.com/joyent/node/issues/search?q=fs.watch