可用性


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

如果底层功能由于某些原因不可用,则 fs.watch 将无法运行。 例如,当使用虚拟化软件(如 Vagrant、Docker 等)时,在网络文件系统(NFS、SMB 等)或主文件系统上监视文件或目录可能是不可靠的,在某些情况下也是不可能的。

仍然可以使用 fs.watchFile(),因为它使用 stat 轮询 ,但这种方法较慢且不太可靠。

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

If the underlying functionality is not available for some reason, then fs.watch will not be able to function. 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, Docker, etc.

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