Use Chokidar to view a specific file extension.

I am looking to view a folder using nodejs Chokidar I only want to keep track of additions, delete xml files. I am new to Chokidar and cannot understand. I tried setting Chokidar ignore to match all lines that end in .xml, but it looks like Chokidar ignore accepts a negative expression

Even the example below does not work

watcher = chokidar.watch(watcherFolder, { 
    ignored: /[^l]$,
    persistent: true,
    ignoreInitial: true,
    alwaysState: true}
);

Is there a way to do this or do I need to add a filter to the callback function?

watcher.on('add', function(path) {
    if (!/\.xml$/i.test(path)) { return; }
    console.log('chokidar: add: ' + path);
});
watcher.on('unlink', function(path) {
    if (!/\.xml$/i.test(path)) { return; }
    console.log('chokidar: unlink: ' + path);
});

watcher.on('change', function(path) {
    if (!/\.xml$/i.test(path)) { return; }
    console.log('chokidar: change: ' + path);
});
+4
source share
1 answer

chokidartakes the glob pattern as the first argument.
You can use it according to your XML files.

chokidar.watch("some/directory/**/*.xml", config)
+10

Source: https://habr.com/ru/post/1660086/


All Articles