UNPKG

1.29 kBMarkdownView Raw
1# find-up [![Build Status](https://travis-ci.org/sindresorhus/find-up.svg?branch=master)](https://travis-ci.org/sindresorhus/find-up)
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
28var findUp = require('find-up');
29
30findUp('unicorn.png').then(function (filepath) {
31 console.log(filepath);
32 //=> '/Users/sindresorhus/unicorn.png'
33});
34```
35
36
37## API
38
39### findUp(filename, [options])
40
41Returns a promise that resolves to a filepath or `null`.
42
43### findUp.sync(filename, [options])
44
45Returns a filepath or `null`.
46
47#### filename
48
49Type: `string`
50
51Filename of the file to find.
52
53#### options
54
55##### cwd
56
57Type: `string`
58Default: `process.cwd()`
59
60Directory 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 a npm package
68
69
70## License
71
72MIT © [Sindre Sorhus](http://sindresorhus.com)