UNPKG

789 BMarkdownView Raw
1# pathExists(file[, callback])
2
3Test whether or not the given path exists by checking with the file system. Like [`fs.exists`](https://nodejs.org/api/fs.html#fs_fs_exists_path_callback), but with a normal callback signature (err, exists). Uses `fs.access` under the hood.
4
5- `file` `<String>`
6- `callback` `<Function>`
7
8## Example:
9
10```js
11const fs = require('fs-extra')
12
13const file = '/tmp/this/path/does/not/exist/file.txt'
14
15// With a callback:
16fs.pathExists(file, (err, exists) => {
17 console.log(err) // => null
18 console.log(exists) // => false
19})
20
21// Promise usage:
22fs.pathExists(file)
23 .then(exists => console.log(exists)) // => false
24
25// With async/await:
26async function example (f) {
27 const exists = await fs.pathExists(f)
28
29 console.log(exists) // => false
30}
31
32example(file)
33```