aad8dd855f6ac2ab2a6577c69370c9d80c70018dd2c3f0396eff565f2dd15c0edccebc39301a2bac70c7afcaddf4a5b0b78d34baca37197934db10f2ee7d72 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. # pkg-dir [![Build Status](https://travis-ci.org/sindresorhus/pkg-dir.svg?branch=master)](https://travis-ci.org/sindresorhus/pkg-dir)
  2. > Find the root directory of a npm package
  3. ## Install
  4. ```
  5. $ npm install --save pkg-dir
  6. ```
  7. ## Usage
  8. ```
  9. /
  10. └── Users
  11. └── sindresorhus
  12. └── foo
  13. ├── package.json
  14. └── bar
  15. ├── baz
  16. └── example.js
  17. ```
  18. ```js
  19. // example.js
  20. var pkgDir = require('pkg-dir');
  21. pkgDir(__dirname).then(function (rootPath) {
  22. console.log(rootPath);
  23. //=> '/Users/sindresorhus/foo'
  24. });
  25. ```
  26. ## API
  27. ### pkgDir([cwd])
  28. Returns a promise that resolves to the package root path or `null`.
  29. ### pkgDir.sync([cwd])
  30. Returns the package root path or `null`.
  31. #### cwd
  32. Type: `string`
  33. Default: `process.cwd()`
  34. Directory to start from.
  35. ## Related
  36. - [pkg-dir-cli](https://github.com/sindresorhus/pkg-dir-cli) - CLI for this module
  37. - [find-up](https://github.com/sindresorhus/find-up) - Find a file by walking up parent directories
  38. ## License
  39. MIT © [Sindre Sorhus](http://sindresorhus.com)