# pkg-dir

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

Latest version **9.0.0** (published 2025-06-05) · MIT license · 0 weekly downloads

> **Deprecated.** See documentation for alternatives

> **Better alternative:** See documentation for alternatives (https://github.com/AikidoSec/module-replacements/blob/main/docs/pkg-dir)

## Install

```sh
npm install pkg-dir
pnpm add pkg-dir
yarn add pkg-dir
bun add pkg-dir
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 9.0.0 |
| Published | 2025-06-05 |
| First published | 2015-09-01 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM |
| Node | >=18 |
| Dependencies | 1 |
| Unpacked size | 4.8 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/pkg-dir
- Repository: https://github.com/sindresorhus/pkg-dir
- Homepage: https://github.com/sindresorhus/pkg-dir#readme
- Issues: https://github.com/sindresorhus/pkg-dir/issues
- Funding: https://github.com/sponsors/sindresorhus
- npm.io page: https://npm.io/package/pkg-dir

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

- 9.0.0 (latest) — 2025-06-05
- 8.0.0 — 2023-11-03
- 7.0.0 — 2022-08-16
- 6.0.1 — 2021-10-06
- 6.0.0 — 2021-10-02
- 5.0.0 — 2020-10-16
- 4.2.0 — 2019-05-21
- 4.1.0 — 2019-04-05
- 4.0.0 — 2019-03-12
- 3.0.0 — 2018-06-18
- 2.0.0 — 2017-05-04
- 1.0.0 — 2015-09-01

## README

# pkg-dir

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

## Install

```sh
npm install pkg-dir
```

## Usage

```
/
└── Users
    └── sindresorhus
        └── foo
            ├── package.json
            └── bar
                ├── baz
                └── example.js
```

```js
// example.js
import {packageDirectory} from 'pkg-dir';

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

- [pkg-dir-cli](https://github.com/sindresorhus/pkg-dir-cli) - CLI for this module
- [pkg-up](https://github.com/sindresorhus/pkg-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/pkg-dir · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
