-
-
Notifications
You must be signed in to change notification settings - Fork 35.4k
fs.isWatchAvailable() [capabilities check for fs.watch()] #29894
Copy link
Copy link
Closed
Labels
feature requestIssues that request new features to be added to Node.js.Issues that request new features to be added to Node.js.fsIssues and PRs related to the fs subsystem / file system.Issues and PRs related to the fs subsystem / file system.libuvIssues and PRs related to the libuv dependency or the uv binding.Issues and PRs related to the libuv dependency or the uv binding.
Metadata
Metadata
Assignees
Labels
feature requestIssues that request new features to be added to Node.js.Issues that request new features to be added to Node.js.fsIssues and PRs related to the fs subsystem / file system.Issues and PRs related to the fs subsystem / file system.libuvIssues and PRs related to the libuv dependency or the uv binding.Issues and PRs related to the libuv dependency or the uv binding.
Is your feature request related to a problem? Please describe.
The
fs.watch()File System method is handy and useful. Application and module developers are incented to use it for its advantages overfs.watchFile(). However, it is inconsistent across platforms, and the documentation states that it "is unavailable in some situations."Application developers lack a good way of knowing whether the API is even available, making it diffucult to write portable JavaScript code. The documentation does a nice job of hitting some of the platforms and conditions, but it would be tedious for a developer to write logic around this, not to mention managing periodic updates as new conditions/platforms are added.
Describe the solution you'd like
I'd like for a new method to be available in
fsto check whetherwatch()is available. That way, portable code can be written that "falls back" tofs.watchFile()if feasible.Not only would this enable portability, it would enable OS-specific conditions to be checked within the Node.js implementation. For example, the AIX implementation could check whether AHAFS is enabled.
Even further, if the new
isWatchAvailable()method could take a directory as a parameter, then its implementation could also check whetherfs.watch()would function on objects within that directory (and therefore say "no" for SMB shares, etc).Describe alternatives you've considered
Implementations could throw a specific Exception/Error if the platform doesn't support
fs.watch(). However, it seems like the behavior is completely unspecified when the function is not available.