Projekt

Obecné

Profil

Stáhnout (1.22 KB) Statistiky
| Větev: | Revize:
1 3a515b92 cagy
# pkg-dir [![Build Status](https://travis-ci.org/sindresorhus/pkg-dir.svg?branch=master)](https://travis-ci.org/sindresorhus/pkg-dir)
2
3
> Find the root directory of a Node.js project or npm package
4
5
6
## Install
7
8
```
9
$ npm install pkg-dir
10
```
11
12
13
## Usage
14
15
```
16
/
17
└── Users
18
    └── sindresorhus
19
        └── foo
20
            ├── package.json
21
            └── bar
22
                ├── baz
23
                └── example.js
24
```
25
26
```js
27
// example.js
28
const pkgDir = require('pkg-dir');
29
30
(async () => {
31
	const rootDir = await pkgDir(__dirname);
32
33
	console.log(rootDir);
34
	//=> '/Users/sindresorhus/foo'
35
})();
36
```
37
38
39
## API
40
41
### pkgDir([cwd])
42
43
Returns a `Promise` for either the project root path or `null` if it couldn't be found.
44
45
### pkgDir.sync([cwd])
46
47
Returns the project root path or `null`.
48
49
#### cwd
50
51
Type: `string`<br>
52
Default: `process.cwd()`
53
54
Directory to start from.
55
56
57
## Related
58
59
- [pkg-dir-cli](https://github.com/sindresorhus/pkg-dir-cli) - CLI for this module
60
- [pkg-up](https://github.com/sindresorhus/pkg-up) - Find the closest package.json file
61
- [find-up](https://github.com/sindresorhus/find-up) - Find a file by walking up parent directories
62
63
64
## License
65
66
MIT © [Sindre Sorhus](https://sindresorhus.com)