# package-directory

> Find the root directory of a Node.js project or npm package

Latest version **8.2.0** (published 2026-02-01) · MIT license · 0 weekly downloads

## Install

```sh
npm install package-directory
pnpm add package-directory
yarn add package-directory
bun add package-directory
```

## Health

**Score 65/100 (B)** — status: stable.

Positive: has types; esm support; no vulnerabilities; high maintenance score; high quality score.

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 8.2.0 |
| Published | 2026-02-01 |
| First published | 2017-05-19 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM |
| Node | >=18 |
| Dependencies | 1 |
| Unpacked size | 7.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 253 |
| Author | Sindre Sorhus |
| Maintainers | sindresorhus |
| Keywords | package, json, root, npm, entry, find, up, find-up, findup, look-up, look, file, search, match, resolve, parent, parents, folder, directory, walk, walking, path |

## Links

- npm: https://www.npmjs.com/package/package-directory
- Repository: https://github.com/sindresorhus/package-directory
- Homepage: https://github.com/sindresorhus/package-directory#readme
- Issues: https://github.com/sindresorhus/package-directory/issues
- Funding: https://github.com/sponsors/sindresorhus
- npm.io page: https://npm.io/package/package-directory

## Dependencies (1)

- [find-up-simple](https://npm.io/package/find-up-simple.md) ^1.0.0

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 8.2.0 (latest) — 2026-02-01
- 8.1.0 — 2025-06-05
- 0.2.3 — 2017-05-19
- 0.2.2 — 2017-05-19
- 0.2.1 — 2017-05-19
- 0.2.0 — 2017-05-19
- 0.1.6 — 2017-05-19
- 0.1.5 — 2017-05-19
- 0.1.4 — 2017-05-19
- 0.1.3 — 2017-05-19

## 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.

##### ignoreTypeOnlyPackageJson

Type: `boolean`\
Default: `false`

Ignore `package.json` files that only contain the `type` field.

This treats `{"type":"module"}` files as ESM scope markers instead of package roots.

## 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

---
_Source: https://npm.io/package/package-directory · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
