# fd-package-json

> Utilities for finding the closest package.json file

Latest version **2.0.0** (published 2025-05-26) · MIT license · 0 weekly downloads

## Install

```sh
npm install fd-package-json
pnpm add fd-package-json
yarn add fd-package-json
bun add fd-package-json
```

## Health

**Score 55/100 (C)** — status: stable.

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

Warnings: low downloads.

Negative: stale.

## Facts

| | |
|---|---|
| Version | 2.0.0 |
| Published | 2025-05-26 |
| First published | 2024-03-03 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Unpacked size | 7.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 13 |
| Author | James Garbutt |
| Maintainers | 43081j |
| Keywords | package-json, find-pkg, pkg-up, find-up, find, walk, parents, parent |

## Links

- npm: https://www.npmjs.com/package/fd-package-json
- Repository: https://github.com/es-tooling/fd-package-json
- Homepage: https://github.com/es-tooling/fd-package-json#readme
- Issues: https://github.com/es-tooling/fd-package-json/issues
- npm.io page: https://npm.io/package/fd-package-json

## Dependencies (1)

- [walk-up-path](https://npm.io/package/walk-up-path.md) ^4.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

- 2.0.0 (latest) — 2025-05-26
- 2.0.0-beta.0 (next) — 2024-06-18
- 1.2.0 — 2024-03-09
- 1.1.0 — 2024-03-05
- 1.0.0 — 2024-03-03
- 0.0.1 — 2024-03-03

## README

# fd-package-json

Finds the closest `package.json` and returns the path or the contents.

## Install

```sh
npm i -S fd-package-json
```

## Usage

To retrieve the path of the closest package, you can use `findPackagePath`:

```ts
import {findPackagePath} from 'fd-package-json';

// Closest package path to cwd of the process
await findPackagePath(process.cwd());

// Closest package path to the current file (CJS)
await findPackagePath(__dirname);

// Closest package path to the current file (ESM)
await findPackagePath(fileURLToPath(new URL('.', import.meta.url)));
```

To retrieve the package itself, you may use `findPackage` with the same
parameter:

```ts
await findPackage(process.cwd()); // Returns the JSON of the package if found
```

Synchronous methods also exist:

```ts
findPackageSync(process.cwd()); // returns the package

findPackagePathSync(process.cwd()); // returns the package path
```

## License

MIT

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