1 | # pathExists(file[, callback])
|
2 |
|
3 | Test 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
|
11 | const fs = require('fs-extra')
|
12 |
|
13 | const file = '/tmp/this/path/does/not/exist/file.txt'
|
14 |
|
15 | // With a callback:
|
16 | fs.pathExists(file, (err, exists) => {
|
17 | console.log(err) // => null
|
18 | console.log(exists) // => false
|
19 | })
|
20 |
|
21 | // Promise usage:
|
22 | fs.pathExists(file)
|
23 | .then(exists => console.log(exists)) // => false
|
24 |
|
25 | // With async/await:
|
26 | async function example (f) {
|
27 | const exists = await fs.pathExists(f)
|
28 |
|
29 | console.log(exists) // => false
|
30 | }
|
31 |
|
32 | example(file)
|
33 | ```
|