1

Im looking for a way to notice changes in a directory in Node.js. I read THIS and was thinking thats exactly what i want. But chokidar spawns to many events.

My code looks like this:

chokidar = require('chokidar');

var watcher = chokidar.watch('./Update', {ignored: /[\/\\]\./, persistent: true});
var count=0;
watcher
    .on('add', function(path) 
    {
        count++;
        console.log('File ' + path + ' has been added' + count);    
    })

    .on('error', function(error) {console.error('Error happened', error);})

When i run it and move a file in the Update directory i get the following output:

File Update\Neues Textdokument.txt has been added1

File Update\Neues Textdokument.txt has been added2

File Update\Neues Textdokument.txt has been added3

In the future i want to replace the console output with code that actualy does something, so i cant have moving one file spawning 3 events. Am I using the libary wrong? Or is the libary just not suited for what I want to do? If so what libary should i use instead?

Community
  • 1
  • 1
Thomas D
  • 83
  • 6
  • Try the latest version of chokidar. Many inconsistencies in the events it emits have been fixed recently. – es128 Oct 30 '14 at 13:51

2 Answers2

0

try the following patch:

https://github.com/paulmillr/chokidar/pull/124

as stated in

https://github.com/paulmillr/chokidar/issues/104

Qiong Wu
  • 1,504
  • 1
  • 15
  • 27
0

In the end I am using version 0.7.1 of chokidar. It works fine as long the folder is empty at the moment the file is added, but im still looking for a better solution

Thomas D
  • 83
  • 6