readme.md
1 # read-pkg [](https://travis-ci.org/sindresorhus/read-pkg) 2 3 > Read a package.json file 4 5 6 ## Why 7 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 13 ## Install 14 15 ``` 16 $ npm install read-pkg 17 ``` 18 19 20 ## Usage 21 22 ```js 23 const readPkg = require('read-pkg'); 24 25 (async () => { 26 console.log(await readPkg()); 27 //=> {name: 'read-pkg', …} 28 29 console.log(await readPkg({cwd: 'some-other-directory'})); 30 //=> {name: 'unicorn', …} 31 })(); 32 ``` 33 34 35 ## API 36 37 ### readPkg(options?) 38 39 Returns a `Promise<object>` with the parsed JSON. 40 41 ### readPkg.sync(options?) 42 43 Returns the parsed JSON. 44 45 #### options 46 47 Type: `object` 48 49 ##### cwd 50 51 Type: `string`<br> 52 Default: `process.cwd()` 53 54 Current working directory. 55 56 ##### normalize 57 58 Type: `boolean`<br> 59 Default: `true` 60 61 [Normalize](https://github.com/npm/normalize-package-data#what-normalization-currently-entails) the package data. 62 63 64 ## Related 65 66 - [read-pkg-up](https://github.com/sindresorhus/read-pkg-up) - Read the closest package.json file 67 - [write-pkg](https://github.com/sindresorhus/write-pkg) - Write a `package.json` file 68 - [load-json-file](https://github.com/sindresorhus/load-json-file) - Read and parse a JSON file 69 70 71 --- 72 73 <div align="center"> 74 <b> 75 <a href="https://tidelift.com/subscription/pkg/npm-read-pkg?utm_source=npm-read-pkg&utm_medium=referral&utm_campaign=readme">Get professional support for this package with a Tidelift subscription</a> 76 </b> 77 <br> 78 <sub> 79 Tidelift helps make open source sustainable for maintainers while giving companies<br>assurances about security, maintenance, and licensing for their dependencies. 80 </sub> 81 </div>