paths-exist
Getting Started
Install
npm install paths-exist -SAdd to source
;API
pathsExist(<String> pathToCheck, <fs.constants> fsFlag)
Where
pathToCheckis a single path string you want to check.fsFlagis an optional param where you can specify the expected file mode; F_OK is the default.
; async { await ; // --> return null (because path param is empty) await ; // --> return true await ; // --> return true await ; // --> return false await ; // --> return true await ; // --> return true};pathsExist(<Array> pathsToCheck, <fs.constants> fsFlag)
Where
pathsToCheckis an array of path strings you want to check.fsFlagis an optional param where you can specify the expected file mode; F_OK is the default.
; async { await ; // --> return null (because path param is empty) await ; // --> return true await ; // --> return true await ; // --> return true await ; // --> return false await ; // --> return false};FAQ
Why
Sindre already has a small-bundled version for path-checking: path-exists. I wanted an API that was overloaded with the ability to check for an array of paths. While it would be quite simple to implement a factory, I ended up needing this functionality across a few different projects in a week and decided to abstract it.How
- File checks are done using
fs.accesswith the default constantfs.constants.F_OK. - You can overload this file constant with
F_OK,W_OKorR_OK(as well as pairings eg.W_OK | R_OK). - You can read more about the file constants here: File Access Constant
fs.constants
| Name | Description |
|---|---|
F_OK |
file is accessible |
R_OK |
file is readable |
W_OK |
file is writable |