Read a package.json file
npm install read-pkg> Read a package.json file
- Throws more helpful JSON errors
- Normalizes the data
``sh`
npm install read-pkg
`js
import {readPackage} from 'read-pkg';
console.log(await readPackage());
//=> {name: 'read-pkg', …}
console.log(await readPackage({cwd: 'some-other-directory'}));
//=> {name: 'unicorn', …}
`
Returns a Promise
Returns the parsed JSON.
#### options
Type: object
##### cwd
Type: URL | string\process.cwd()
Default:
Current working directory.
##### normalize
Type: boolean\true
Default:
Normalize the package data.
Parses an object or string into JSON.
#### packageFile
Type: object | string
An object or a stringified object to be parsed as a package.json.
#### options
Type: object
##### normalize
Type: boolean\true
Default:
Normalize the package data.
- read-package-up - Read the closest package.json file
- write-package - Write a package.json` file
- load-json-file - Read and parse a JSON file