1 | # find-up [![Build Status: Linux and macOS](https://travis-ci.org/sindresorhus/find-up.svg?branch=master)](https://travis-ci.org/sindresorhus/find-up) [![Build Status: Windows](https://ci.appveyor.com/api/projects/status/l0cyjmvh5lq72vq2/branch/master?svg=true)](https://ci.appveyor.com/project/sindresorhus/find-up/branch/master)
|
2 |
|
3 | > Find a file by walking up parent directories
|
4 |
|
5 |
|
6 | ## Install
|
7 |
|
8 | ```
|
9 | $ npm install --save find-up
|
10 | ```
|
11 |
|
12 |
|
13 | ## Usage
|
14 |
|
15 | ```
|
16 | /
|
17 | └── Users
|
18 | └── sindresorhus
|
19 | ├── unicorn.png
|
20 | └── foo
|
21 | └── bar
|
22 | ├── baz
|
23 | └── example.js
|
24 | ```
|
25 |
|
26 | ```js
|
27 | // example.js
|
28 | const findUp = require('find-up');
|
29 |
|
30 | findUp('unicorn.png').then(filepath => {
|
31 | console.log(filepath);
|
32 | //=> '/Users/sindresorhus/unicorn.png'
|
33 | });
|
34 | ```
|
35 |
|
36 |
|
37 | ## API
|
38 |
|
39 | ### findUp(filename, [options])
|
40 |
|
41 | Returns a `Promise` for the filepath or `null`.
|
42 |
|
43 | ### findUp.sync(filename, [options])
|
44 |
|
45 | Returns a filepath or `null`.
|
46 |
|
47 | #### filename
|
48 |
|
49 | Type: `string`
|
50 |
|
51 | Filename of the file to find.
|
52 |
|
53 | #### options
|
54 |
|
55 | ##### cwd
|
56 |
|
57 | Type: `string`
|
58 | Default: `process.cwd()`
|
59 |
|
60 | Directory to start from.
|
61 |
|
62 |
|
63 | ## Related
|
64 |
|
65 | - [find-up-cli](https://github.com/sindresorhus/find-up-cli) - CLI for this module
|
66 | - [pkg-up](https://github.com/sindresorhus/pkg-up) - Find the closest package.json file
|
67 | - [pkg-dir](https://github.com/sindresorhus/pkg-dir) - Find the root directory of an npm package
|
68 |
|
69 |
|
70 | ## License
|
71 |
|
72 | MIT © [Sindre Sorhus](https://sindresorhus.com)
|