e1235294d46bf81f318d365d88d48b7bd699dddf1da3082de5ac3440894b14e82552e5978041631d734437dcfad0641d53a8f842ea33f41ceecaf0ef70137c 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. # find-up [![Build Status](https://travis-ci.org/sindresorhus/find-up.svg?branch=master)](https://travis-ci.org/sindresorhus/find-up)
  2. > Find a file by walking up parent directories
  3. ## Install
  4. ```
  5. $ npm install --save find-up
  6. ```
  7. ## Usage
  8. ```
  9. /
  10. └── Users
  11. └── sindresorhus
  12. ├── unicorn.png
  13. └── foo
  14. └── bar
  15. ├── baz
  16. └── example.js
  17. ```
  18. ```js
  19. // example.js
  20. const findUp = require('find-up');
  21. findUp('unicorn.png').then(filepath => {
  22. console.log(filepath);
  23. //=> '/Users/sindresorhus/unicorn.png'
  24. });
  25. ```
  26. ## API
  27. ### findUp(filename, [options])
  28. Returns a promise for the filepath or `null`.
  29. ### findUp.sync(filename, [options])
  30. Returns a filepath or `null`.
  31. #### filename
  32. Type: `string`
  33. Filename of the file to find.
  34. #### options
  35. ##### cwd
  36. Type: `string`
  37. Default: `process.cwd()`
  38. Directory to start from.
  39. ## Related
  40. - [find-up-cli](https://github.com/sindresorhus/find-up-cli) - CLI for this module
  41. - [pkg-up](https://github.com/sindresorhus/pkg-up) - Find the closest package.json file
  42. - [pkg-dir](https://github.com/sindresorhus/pkg-dir) - Find the root directory of an npm package
  43. ## License
  44. MIT © [Sindre Sorhus](http://sindresorhus.com)