1

I am using fs.watchfile(); in NodeJS somewhat like the documentation example:

fs.watchFile('message.text', function (curr, prev) {});

When I use a listener:

fs.watchFile('message.text', function (curr, prev) {}, listener);

And unwatch the file:

fs.unwatchFile(message.text, listener);

The unwatchfile removes all listeners to the file instead of the specified listener. The documentation states that it should only remove the specified listener, so what is being done incorrectly?

hexacyanide
  • 88,222
  • 31
  • 159
  • 162

1 Answers1

3

Second parameter in fs.watchFile will be an JavaScript object with options but you passed two functions.

Test case:

var fs = require('fs');
var listener1 = function (curr, prev) { console.log('touched 1'); };
var listener2 = function (curr, prev) { console.log('touched 2'); };

fs.watchFile('message.text', listener1);
fs.watchFile('message.text', listener2);

fs.unwatchFile('message.text', listener1);
Vadim Baryshev
  • 25,689
  • 4
  • 56
  • 48