wallet-core/node_modules/pkg-dir/readme.md

65 lines
1.2 KiB
Markdown
Raw Normal View History

2017-05-28 00:38:50 +02:00
# pkg-dir [![Build Status](https://travis-ci.org/sindresorhus/pkg-dir.svg?branch=master)](https://travis-ci.org/sindresorhus/pkg-dir)
2017-08-14 05:01:11 +02:00
> Find the root directory of a Node.js project or npm package
2017-05-28 00:38:50 +02:00
## Install
```
$ npm install --save pkg-dir
```
## Usage
```
/
└── Users
└── sindresorhus
└── foo
├── package.json
└── bar
├── baz
└── example.js
```
```js
// example.js
2017-08-14 05:01:11 +02:00
const pkgDir = require('pkg-dir');
2017-05-28 00:38:50 +02:00
2017-08-14 05:01:11 +02:00
pkgDir(__dirname).then(rootDir => {
console.log(rootDir);
2017-05-28 00:38:50 +02:00
//=> '/Users/sindresorhus/foo'
});
```
## API
### pkgDir([cwd])
2017-08-14 05:01:11 +02:00
Returns a `Promise` for either the project root path or `null` if it couldn't be found.
2017-05-28 00:38:50 +02:00
### pkgDir.sync([cwd])
2017-08-14 05:01:11 +02:00
Returns the project root path or `null`.
2017-05-28 00:38:50 +02:00
#### cwd
2017-08-14 05:01:11 +02:00
Type: `string`<br>
2017-05-28 00:38:50 +02:00
Default: `process.cwd()`
Directory to start from.
## Related
- [pkg-dir-cli](https://github.com/sindresorhus/pkg-dir-cli) - CLI for this module
2017-08-14 05:01:11 +02:00
- [pkg-up](https://github.com/sindresorhus/pkg-up) - Find the closest package.json file
2017-05-28 00:38:50 +02:00
- [find-up](https://github.com/sindresorhus/find-up) - Find a file by walking up parent directories
## License
2017-08-14 05:01:11 +02:00
MIT © [Sindre Sorhus](https://sindresorhus.com)