2022-05-29 09:24:36 +00:00
|
|
|
# find-up [![Build Status](https://travis-ci.org/sindresorhus/find-up.svg?branch=master)](https://travis-ci.org/sindresorhus/find-up)
|
|
|
|
|
|
|
|
> Find a file by walking up parent directories
|
2022-01-21 08:28:41 +00:00
|
|
|
|
|
|
|
|
|
|
|
## Install
|
|
|
|
|
|
|
|
```
|
2022-05-29 09:24:36 +00:00
|
|
|
$ npm install --save find-up
|
2022-01-21 08:28:41 +00:00
|
|
|
```
|
|
|
|
|
2022-05-29 09:24:36 +00:00
|
|
|
|
2022-01-21 08:28:41 +00:00
|
|
|
## Usage
|
|
|
|
|
|
|
|
```
|
|
|
|
/
|
|
|
|
└── Users
|
|
|
|
└── sindresorhus
|
|
|
|
├── unicorn.png
|
|
|
|
└── foo
|
|
|
|
└── bar
|
|
|
|
├── baz
|
|
|
|
└── example.js
|
|
|
|
```
|
|
|
|
|
|
|
|
```js
|
2022-05-29 09:24:36 +00:00
|
|
|
// example.js
|
2022-01-21 08:28:41 +00:00
|
|
|
const findUp = require('find-up');
|
|
|
|
|
2022-05-29 09:24:36 +00:00
|
|
|
findUp('unicorn.png').then(filepath => {
|
|
|
|
console.log(filepath);
|
2022-01-21 08:28:41 +00:00
|
|
|
//=> '/Users/sindresorhus/unicorn.png'
|
2022-05-29 09:24:36 +00:00
|
|
|
});
|
2022-04-07 13:41:52 +00:00
|
|
|
```
|
2022-01-21 08:28:41 +00:00
|
|
|
|
2022-04-07 13:41:52 +00:00
|
|
|
|
2022-05-29 09:24:36 +00:00
|
|
|
## API
|
2022-01-21 08:28:41 +00:00
|
|
|
|
2022-05-29 09:24:36 +00:00
|
|
|
### findUp(filename, [options])
|
2022-01-21 08:28:41 +00:00
|
|
|
|
2022-05-29 09:24:36 +00:00
|
|
|
Returns a promise for the filepath or `null`.
|
2022-01-21 08:28:41 +00:00
|
|
|
|
2022-05-29 09:24:36 +00:00
|
|
|
### findUp.sync(filename, [options])
|
2022-01-21 08:28:41 +00:00
|
|
|
|
2022-05-29 09:24:36 +00:00
|
|
|
Returns a filepath or `null`.
|
2022-04-07 13:41:52 +00:00
|
|
|
|
2022-05-29 09:24:36 +00:00
|
|
|
#### filename
|
2022-01-21 08:28:41 +00:00
|
|
|
|
|
|
|
Type: `string`
|
|
|
|
|
2022-05-29 09:24:36 +00:00
|
|
|
Filename of the file to find.
|
2022-01-21 08:28:41 +00:00
|
|
|
|
|
|
|
#### options
|
|
|
|
|
|
|
|
##### cwd
|
|
|
|
|
2022-05-29 09:24:36 +00:00
|
|
|
Type: `string`
|
2022-01-21 08:28:41 +00:00
|
|
|
Default: `process.cwd()`
|
|
|
|
|
|
|
|
Directory to start from.
|
|
|
|
|
|
|
|
|
|
|
|
## Related
|
|
|
|
|
|
|
|
- [find-up-cli](https://github.com/sindresorhus/find-up-cli) - CLI for this module
|
|
|
|
- [pkg-up](https://github.com/sindresorhus/pkg-up) - Find the closest package.json file
|
|
|
|
- [pkg-dir](https://github.com/sindresorhus/pkg-dir) - Find the root directory of an npm package
|
2022-05-29 09:24:36 +00:00
|
|
|
|
|
|
|
|
|
|
|
## License
|
|
|
|
|
|
|
|
MIT © [Sindre Sorhus](http://sindresorhus.com)
|