The accessSync
function from the fs-extra
package provides a synchronous way to check the accessibility of a file or a directory. Here's how to use it:
index.tsx342 chars10 lines
In the code above, we require fs-extra
and then try to access a file or directory at the specified path. The second argument is a bit mask indicating the accessibility mode we want to use. In this case, we use fs.constants.R_OK
and fs.constants.W_OK
to check if the file or directory is both readable and writable. If an error is thrown, we log an error message indicating that the file or directory is not accessible.
Note that accessSync
is a synchronous function, so it will block the execution of your code until it finishes checking the accessibility of the file or directory.
gistlibby LogSnag