pathExists(file[, callback])

Test whether or not the given path exists by checking with the file system. Like fs.exists, but with a normal callback signature (err, exists). Uses fs.access under the hood.

  • file <String>
  • callback <Function>

Example:

  1. const fs = require('fs-extra')
  2. const file = '/tmp/this/path/does/not/exist/file.txt'
  3. // Promise usage:
  4. fs.pathExists(file)
  5. .then(exists => console.log(exists)) // => false
  6. // Callback usage:
  7. fs.pathExists(file, (err, exists) => {
  8. console.log(err) // => null
  9. console.log(exists) // => false
  10. })