Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Chokidar add event fired for all files in folder

Tags:

node.js

When I use "add" event for watching a folder with Chokidar all existing files are listed as added.

Is this the correct behavior?

How can I prevent existing files from being listed and only show files that gets added?

The "change" event works as expected.

var watcher = chokidar.watch('/My/path', {
  ignored: /[\/\\]\./,
  persistent: true
});    

watcher
      .on('change',  function(path) { console.log("File " + path + " has been changed"); })
      .on('add',  function(path) {  console.log("File " + path + " has been added"); });

I'm using [email protected]

/Christian

like image 746
Christian Avatar asked Apr 04 '16 21:04

Christian


Video Answer


1 Answers

Try using the ignoreInitial option:

const watcher = chokidar.watch(DIR_PATH, {
  ignoreInitial:true
});
like image 53
wtk Avatar answered Sep 21 '22 17:09

wtk