You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

readme.md 1.2KB

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)