开发者

Filesystem watcher using node.js

I want to implement file system watcher using node.js so that it watches a particular directory for any files being added/delete开发者_Python百科d. Can somebody give an idea how to implement this?

Thanks


check out fs.watchFile(filename, [options], listener) for the inbuilt file system watching


The core node.js watching will trigger a change event on the parent directory when a file is deleted, among other oddities. You can use Watchr to get useful events, and watching directory trees.


As pointed out in comments, the previous answer by @FailingBullets, whilst good to know, really only addresses individual file changes. There is a package here that might help though:

https://github.com/mikeal/watch

I haven't used it yet though I intend to soon. I'll update my answer once I do.


As mentioned by @cbmeeks, the chokidar package is worth looking at. Its README mentions that it's used by webpack, browserify, VS Code, etc, so it's likely quite stable and painless to use. It has > 4k stars as well, so that lends some weight to it.


Another alternative is to use NSFW. It is a native abstraction for Linux, Windows, and OSX file watching services, thus does not suffer from performance issues like others.

https://github.com/Axosoft/nsfw

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜