1 | # path-exists
|
2 |
|
3 | > Check if a path exists
|
4 |
|
5 | NOTE: `fs.existsSync` has been un-deprecated in Node.js since 6.8.0. If you only need to check synchronously, this module is not needed.
|
6 |
|
7 | Never use this before handling a file though:
|
8 |
|
9 | > In particular, checking if a file exists before opening it is an anti-pattern that leaves you vulnerable to race conditions: another process may remove the file between the calls to `fs.exists()` and `fs.open()`. Just open the file and handle the error when it's not there.
|
10 |
|
11 | ## Install
|
12 |
|
13 | ```
|
14 | $ npm install path-exists
|
15 | ```
|
16 |
|
17 | ## Usage
|
18 |
|
19 | ```js
|
20 | // foo.js
|
21 | import {pathExists} from 'path-exists';
|
22 |
|
23 | console.log(await pathExists('foo.js'));
|
24 | //=> true
|
25 | ```
|
26 |
|
27 | ## API
|
28 |
|
29 | ### pathExists(path)
|
30 |
|
31 | Returns a `Promise<boolean>` of whether the path exists.
|
32 |
|
33 | ### pathExistsSync(path)
|
34 |
|
35 | Returns a `boolean` of whether the path exists.
|
36 |
|
37 | ## Related
|
38 |
|
39 | - [path-exists-cli](https://github.com/sindresorhus/path-exists-cli) - CLI for this module
|
40 | - [path-type](https://github.com/sindresorhus/path-type) - Check if a path exists and whether it's a file, directory, or symlink
|
41 |
|
42 | ---
|
43 |
|
44 | <div align="center">
|
45 | <b>
|
46 | <a href="https://tidelift.com/subscription/pkg/npm-path-exists?utm_source=npm-path-exists&utm_medium=referral&utm_campaign=readme">Get professional support for this package with a Tidelift subscription</a>
|
47 | </b>
|
48 | <br>
|
49 | <sub>
|
50 | Tidelift helps make open source sustainable for maintainers while giving companies<br>assurances about security, maintenance, and licensing for their dependencies.
|
51 | </sub>
|
52 | </div>
|