0b9a6b9b966698675d9b5a0386c34fa18d0f7f8efc4f0b0bf47139e6f0596657b2332b4b08fb958f2995edd382f123a6236eecdf4626cd33b703fcdbd2392d 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. # path-exists [![Build Status](https://travis-ci.org/sindresorhus/path-exists.svg?branch=master)](https://travis-ci.org/sindresorhus/path-exists)
  2. > Check if a path exists
  3. Because [`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.
  4. Never use this before handling a file though:
  5. > 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.
  6. ## Install
  7. ```
  8. $ npm install --save path-exists
  9. ```
  10. ## Usage
  11. ```js
  12. // foo.js
  13. var pathExists = require('path-exists');
  14. pathExists('foo.js').then(function (exists) {
  15. console.log(exists);
  16. //=> true
  17. });
  18. ```
  19. ## API
  20. ### pathExists(path)
  21. Returns a promise that resolves to a boolean of whether the path exists.
  22. ### pathExists.sync(path)
  23. Returns a boolean of whether the path exists.
  24. ## License
  25. MIT © [Sindre Sorhus](http://sindresorhus.com)