Skip to content

fs.isWatchAvailable() [capabilities check for fs.watch()] #29894

Closed
@ThePrez

Description

@ThePrez

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 over fs.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 fs to check whether watch() is available. That way, portable code can be written that "falls back" to fs.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 whether fs.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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature requestIssues that request new features to be added to Node.js.fsIssues and PRs related to the fs subsystem / file system.libuvIssues and PRs related to the libuv dependency or the uv binding.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions