可用性


【Availability】

此功能依赖于底层操作系统提供一种方式,以便在文件系统发生更改时收到通知。

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

  • 在 Linux 系统上,这使用 inotify(7)
  • 在 BSD 系统上,这使用 kqueue(2)
  • 在 macOS 上,这对于文件使用 kqueue(2),对于目录使用 FSEvents
  • 在 SunOS 系统(包括 Solaris 和 SmartOS)上,这使用 event ports
  • 在 Windows 系统上,此功能取决于 ReadDirectoryChangesW
  • 在 AIX 系统上,此功能依赖于 AHAFS,必须启用它。
  • 在 IBM i 系统上,此功能不受支持。

如果由于某种原因底层功能不可用,那么 fs.watch() 将无法工作,并可能抛出异常。例如,在网络文件系统(NFS、SMB 等)上,或在使用虚拟化软件(如 Vagrant 或 Docker)时,监视文件或目录可能不可靠,甚至在某些情况下不可能。

【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.】

仍然可以使用 fs.watchFile(),它使用状态轮询,但这种方法更慢且不太可靠。

【It is still possible to use fs.watchFile(), which uses stat polling, but this method is slower and less reliable.】