خرید بک لینک

Vote count: 0

I need to monitor if some files are created/removed from certain directories.

I've tried to use fs.watch:

let dirs = ['/tmp', '/home/user', './some-dir']

dirs.forEach(function(dir) {
   fs.watch(dir, (evt, filename) => {
      if (filename && evt === "rename") {
        console.log(evt, dir, filename)
      }
   })
})

But above code will keep returning latest directory in the array. Which is logical. In the same time, the file was added/removed from another directory.

There are some nice third-party modules around such as https://www.npmjs.com/package/chokidar But it has lots of dependencies, so I'm trying to keep up with native node solution for now.

asked 15 secs ago

برچسب: نویسنده: استخدام کار تاريخ: سه شنبه 19 ارديبهشت 1396 ساعت: 20:25

صفحه بندی