DEV Community

Omar Dulaimi
Omar Dulaimi

Posted on • Updated on

Watch files/directories changes in Nodejs

The ๐—ณ๐˜€๐—ฃ๐—ฟ๐—ผ๐—บ๐—ถ๐˜€๐—ฒ๐˜€.๐˜„๐—ฎ๐˜๐—ฐ๐—ต method returns an async iterator that watches for changes on ๐—ณ๐—ถ๐—น๐—ฒ๐—ป๐—ฎ๐—บ๐—ฒ, where ๐—ณ๐—ถ๐—น๐—ฒ๐—ป๐—ฎ๐—บ๐—ฒ is either a file or a directory.

By default, it uses ๐˜‚๐˜๐—ณ๐Ÿด encoding and keeps the process running as long as the file/dir is being watched.

Optionally, you could pass an ๐—”๐—ฏ๐—ผ๐—ฟ๐˜๐—ฆ๐—ถ๐—ด๐—ป๐—ฎ๐—น to signal when the watcher should stop.

Keep in mind that this API comes with a few caveats. For example, not being consistent across platforms; the recursive option is only supported on macOS and Windows.

So make sure to check all the caveats..


Did you learn something new today?

Like and share this post, and follow me for more!

watch files/dirs

Top comments (0)