Check if filepath exists and is a file. Returns false for directories.
(Requires node >=6.0.0)
npm install file-exists --save
const fileExists = require('file-exists');
fileExists('/index.html', (err, exists) => console.log(exists)) // OUTPUTS: true or false
fileExists('/index.html').then(exists => {
console.log(exists) // OUTPUTS: true or false
})
const exists = await fileExists('/index.html')
console.log(fileExists.sync('/index.html')) // OUTPUTS: true or false
filepath
- the path to the file to check if it existsoptions
- an object of optionsroot
- the root directory to look in (or cwd)
callback(err, exists)
- gets called when checking is done
filepath
- the path to the file to check if it existsoptions
- an object of optionsroot
- the root directory to look in (or cwd)
npm install
npm test