is-file-exists
Check if a file exists
Install
With npm
npm install is-file-exists
With yarn
yarn add is-file-exists
API
isFileExistsAsync(path, [callback])
Check if a file exists, called asynchronously where:
path
- a buffer or a string.callback
- an optional callback method when file checking is completed or failed with the signaturefunction(valid, message)
where:valid
- a boolean value: true when the file exists and false if there is an error.message
- a null value when valid is true and an object when valid is false.
If no callback
is provided, a Promise
object is returned.
isFileExistsSync(path)
Check if a file exists, called synchronously where:
path
- a buffer or a string
Usage examples
Asynchronous and callback
const isFileExistsAsync = ; ; ;
Asynchronous and promise
const isFileExistsAsync = ; ; ;
Synchronous
const isFileExistsSync = ; const resultA = ;if resultA && !resultAvalid console; else console; const resultB = ;if resultB && !resultBvalid console; else console;