fs.watch()
The Node.js function that reports changes to a file or directory using the operating system's notification system.
In more detail
The promise version returns an async iterable of events with an eventType and filename, and stops when its AbortSignal fires. Events can arrive twice or be merged, so treat them as hints to re-check.
Related terms
- inotify — The Linux kernel facility that notifies programs when files or directories are created, changed or deleted.
- kqueue — The event notification facility on macOS and BSD systems, doing the job epoll does on Linux and also reporting file changes.
- async iteration — Looping over values that arrive over time with for await (const x of source), waiting for each one before the next turn of the loop.
- AbortController — The standard JavaScript object for cancelling asynchronous work: its signal is handed to the work, and calling abort() cancels it.
Taught in
- Directory Traversal: Recursive Readdir & fs.watch — Node.js Internals & Backend Services