This feature depends on the underlying operating system providing a way to be notified of filesystem changes.
- On Linux systems, this uses
- On BSD systems, this uses
- On macOS, this uses
kqueue(2)for files and
- On SunOS systems (including Solaris and SmartOS), this uses
- On Windows systems, this feature depends on
- On AIX systems, this feature depends on
AHAFS, which must be enabled.
- On IBM i systems, this feature is not supported.
If the underlying functionality is not available for some reason, then
fs.watch() will not be able to function and may throw an exception.
For example, watching files or directories can be unreliable, and in some
cases impossible, on network file systems (NFS, SMB, etc) or host file systems
when using virtualization software such as Vagrant or Docker.
It is still possible to use
fs.watchFile(), which uses stat polling, but
this method is slower and less reliable.