Name | Date | Size | #Lines | LOC | ||
---|---|---|---|---|---|---|
.. | - | - | ||||
index.js | D | 12-May-2024 | 252 | 18 | 15 | |
license | D | 12-May-2024 | 1.1 KiB | 22 | 17 | |
package.json | D | 12-May-2024 | 1.6 KiB | 73 | 72 | |
readme.md | D | 12-May-2024 | 1.3 KiB | 51 | 27 |
readme.md
1# path-exists [![Build Status](https://travis-ci.org/sindresorhus/path-exists.svg?branch=master)](https://travis-ci.org/sindresorhus/path-exists) 2 3> Check if a path exists 4 5Because [`fs.exists()`](https://nodejs.org/api/fs.html#fs_fs_exists_path_callback) is being [deprecated](https://github.com/iojs/io.js/issues/103), but there's still a genuine use-case of being able to check if a path exists for other purposes than doing IO with it. 6 7Never 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 12## Install 13 14``` 15$ npm install --save path-exists 16``` 17 18 19## Usage 20 21```js 22// foo.js 23const pathExists = require('path-exists'); 24 25pathExists('foo.js').then(exists => { 26 console.log(exists); 27 //=> true 28}); 29``` 30 31 32## API 33 34### pathExists(path) 35 36Returns a promise for a boolean of whether the path exists. 37 38### pathExists.sync(path) 39 40Returns a boolean of whether the path exists. 41 42 43## Related 44 45- [path-exists-cli](https://github.com/sindresorhus/path-exists-cli) - CLI for this module 46 47 48## License 49 50MIT © [Sindre Sorhus](https://sindresorhus.com) 51