blob: cb8e98a2d8a0bd5f40ede4950c726e3dfc6c514c [file] [log] [blame] [view]
Mathias Bynens79e2cf02020-05-29 14:46:171# read-pkg-up [![Build Status](https://travis-ci.org/sindresorhus/read-pkg-up.svg?branch=master)](https://travis-ci.org/sindresorhus/read-pkg-up)
2
3> Read the closest package.json file
4
5## Why
6
7- [Finds the closest package.json](https://github.com/sindresorhus/find-up)
8- [Gracefully handles filesystem issues](https://github.com/isaacs/node-graceful-fs)
9- [Throws more helpful JSON errors](https://github.com/sindresorhus/parse-json)
10- [Normalizes the data](https://github.com/npm/normalize-package-data#what-normalization-currently-entails)
11
12## Install
13
14```
15$ npm install read-pkg-up
16```
17
18## Usage
19
20```js
21const readPkgUp = require('read-pkg-up');
22
23(async () => {
24 console.log(await readPkgUp());
25 /*
26 {
27 packageJson: {
28 name: 'awesome-package',
29 version: '1.0.0',
30
31 },
32 path: '/Users/sindresorhus/dev/awesome-package/package.json'
33 }
34 */
35})();
36```
37
38## API
39
40### readPkgUp(options?)
41
42Returns a `Promise<object>` or `Promise<undefined>` if no `package.json` was found.
43
44### readPkgUp.sync(options?)
45
46Returns the result object or `undefined` if no `package.json` was found.
47
48#### options
49
50Type: `object`
51
52##### cwd
53
54Type: `string`\
55Default: `process.cwd()`
56
57Directory to start looking for a package.json file.
58
59##### normalize
60
61Type: `boolean`\
62Default: `true`
63
64[Normalize](https://github.com/npm/normalize-package-data#what-normalization-currently-entails) the package data.
65
66## read-pkg-up for enterprise
67
68Available as part of the Tidelift Subscription.
69
70The maintainers of read-pkg-up and thousands of other packages are working with Tidelift to deliver commercial support and maintenance for the open source dependencies you use to build your applications. Save time, reduce risk, and improve code health, while paying the maintainers of the exact dependencies you use. [Learn more.](https://tidelift.com/subscription/pkg/npm-read-pkg-up?utm_source=npm-read-pkg-up&utm_medium=referral&utm_campaign=enterprise&utm_term=repo)
71
72## Related
73
74- [read-pkg](https://github.com/sindresorhus/read-pkg) - Read a package.json file
75- [pkg-up](https://github.com/sindresorhus/pkg-up) - Find the closest package.json file
76- [find-up](https://github.com/sindresorhus/find-up) - Find a file by walking up parent directories
77- [pkg-conf](https://github.com/sindresorhus/pkg-conf) - Get namespaced config from the closest package.json