https://github.com/sindresorhus/package-directory
  
  
    Find the root directory of a Node.js project or npm package 
    https://github.com/sindresorhus/package-directory
  
        Last synced: about 1 month ago 
        JSON representation
    
Find the root directory of a Node.js project or npm package
- Host: GitHub
 - URL: https://github.com/sindresorhus/package-directory
 - Owner: sindresorhus
 - License: mit
 - Created: 2015-09-01T07:39:43.000Z (about 10 years ago)
 - Default Branch: main
 - Last Pushed: 2025-06-05T18:32:10.000Z (5 months ago)
 - Last Synced: 2025-08-27T06:57:49.920Z (2 months ago)
 - Language: JavaScript
 - Homepage:
 - Size: 30.3 KB
 - Stars: 246
 - Watchers: 6
 - Forks: 20
 - Open Issues: 2
 - 
            Metadata Files:
            
- Readme: readme.md
 - License: license
 - Security: .github/security.md
 
 
Awesome Lists containing this project
- fucking-awesome-nodejs - package-directory - Find the root directory of an npm package. (Packages / Filesystem)
 - awesome-nodejs - package-directory - Find the root directory of an npm package. (Packages / Filesystem)
 
README
          # package-directory
> Find the root directory of a Node.js project or npm package
## Install
```sh
npm install package-directory
```
## Usage
```
/
└── Users
    └── sindresorhus
        └── foo
            ├── package.json
            └── bar
                ├── baz
                └── example.js
```
```js
// example.js
import {packageDirectory} from 'package-directory';
console.log(await packageDirectory());
//=> '/Users/sindresorhus/foo'
```
## API
### packageDirectory(option?)
Returns a `Promise` for either the project root path or `undefined` if it could not be found.
### packageDirectorySync(options?)
Returns the project root path or `undefined` if it could not be found.
#### options
Type: `object`
##### cwd
Type: `string`\
Default: `process.cwd()`
The directory to start searching from.
## Related
- [package-directory-cli](https://github.com/sindresorhus/package-directory-cli) - CLI for this package
- [package-up](https://github.com/sindresorhus/package-up) - Find the closest package.json file
- [find-up](https://github.com/sindresorhus/find-up) - Find a file by walking up parent directories