admin管理员组

文章数量:1123184

I am trying to set up a script that watches for new folders that are added to a directory called /test.

I am using Chokidar to watch for folder changes. The problem is, it fires an event for the folder it is supposed to be watching.

The script looks like this

import chokidar from "chokidar";

const watchDirectory = async () => {  
  const watcher = chokidar.watch('./test');

  watcher
    .on("addDir", (dirPath) => {
      const dirName = path.basename(dirPath);
      console.log(`Detected new folder: ${dirName}`); // logs: Detected new folder: test
    })
};

watchDirectory();

the addDir event callback runs and thinks that /test has just been added. But /test is the name of the folder I am watching.

How do I get Chokidar to ignore /test and just watch for new folders that are added to the test /test path?

本文标签: javascriptHow to stop chokidar from triggering on root folder it39s watchingStack Overflow