可用性


此功能取决于底层操作系统提供了一种通知文件系统更改的方法。

    This feature depends on the underlying operating system providing a way to be notified of filesystem changes.

    • On Linux systems, this uses inotify(7).
    • On BSD systems, this uses kqueue(2).
    • On macOS, this uses kqueue(2) for files and FSEvents for directories.
    • On SunOS systems (including Solaris and SmartOS), this uses event ports.
    • On Windows systems, this feature depends on ReadDirectoryChangesW.
    • 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.