# parent-package-json

> Find, read and parse the package.json of the parent module

Latest version **3.0.0** (published 2023-06-10) · ISC license · 0 weekly downloads

## Install

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

## Health

**Score 28/100 (F)** — status: abandoned.

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

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 3.0.0 |
| Published | 2023-06-10 |
| First published | 2016-01-08 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | separate (@types/parent-package-json) |
| Module format | ESM + CommonJS |
| Node | >= 18.0.0 |
| Dependencies | 0 |
| Unpacked size | 7.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 7 |
| Author | Max Rittmüller |
| Maintainers | maxrimue |
| Keywords | parent, package.json, find, search, parse, read |

## Links

- npm: https://www.npmjs.com/package/parent-package-json
- Repository: https://github.com/maxrimue/parent-package-json
- Homepage: https://github.com/maxrimue/parentPackageJSON#readme
- Issues: https://github.com/maxrimue/parentPackageJSON/issues
- npm.io page: https://npm.io/package/parent-package-json

## Alternatives

- [csv-to-markdown-table](https://npm.io/package/csv-to-markdown-table.md) — 47.0K weekly downloads
- [@sapphire/ratelimits](https://npm.io/package/@sapphire/ratelimits.md) — 4.4K weekly downloads
- [js-csvparser](https://npm.io/package/js-csvparser.md) — 2.0K weekly downloads
- [@adadapted/js-sdk](https://npm.io/package/@adadapted/js-sdk.md) — 251 weekly downloads
- [@grapecity/spread-sheets-sparklines](https://npm.io/package/@grapecity/spread-sheets-sparklines.md) — 103 weekly downloads

## Recent versions

- 3.0.0 (latest) — 2023-06-10
- 2.0.1 — 2017-08-30
- 2.0.0 — 2016-08-16
- 1.1.0 — 2016-01-09
- 1.0.3 — 2016-01-08
- 1.0.2 — 2016-01-08
- 1.0.1 — 2016-01-08
- 1.0.0 — 2016-01-08

## README

# parent-package-json

Find, read and parse the `package.json` that sits above your module. Provide a custom ignore count or start path to define where to look for a parent package.

```shell
npm install --save parent-package-json
```

```javascript
import parentJSON from "parent-package-json";
```

## Getting Started

To get the nearest parent `package.json`s path, content (as string) or parsed content (using JSON.parse):

```javascript
const parent = parentJSON();

const pathToParentPackageJSON = parent.path.relative;
const parentContentAsString = parent.read();
const parentContentAsObject = parent.parse();

const parentVersion = parentContentAsObject.version;
```

The parent `package.json` is looked up starting from the current working directory of your script. If none is found, paths, `.read()` and `.parse()` will return `undefined`.

## Custom Path and Ignore Count

If you need to determine the parent `package.json` of a custom path instead of the current working directory, which should be the module from which you are running the code, you can specify it via the `path` option:

```javascript
const startPath = path.join(...);
const parent = parent({ startPath });
```

You can also specify a count of parent directories to skip:

```javascript
const parent = parent({ ignoreCount: 1 });
```

**Note**: A `package.json` file in the provided `startPath` is always ignored. Set the `startPath` one layer below the one where you expect to find a parent package file.

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