Read the closest package.json file
npm install read-package-up> Read the closest package.json file
- Finds the closest package.json
- Throws more helpful JSON errors
- Normalizes the data
``sh`
npm install read-package-up
`js
import {readPackageUp} from 'read-package-up';
console.log(await readPackageUp());
/*
{
packageJson: {
name: 'awesome-package',
version: '1.0.0',
…
},
path: '/Users/sindresorhus/dev/awesome-package/package.json'
}
*/
`
Returns a Promise
Returns the result object, or undefined if no package.json was found.
#### options
Type: object
##### cwd
Type: URL | string\process.cwd()
Default:
The directory to start looking for a package.json file.
##### normalize
Type: boolean\true`
Default:
Normalize the package data.
- read-pkg - Read a package.json file
- package-up - Find the closest package.json file
- find-up - Find a file by walking up parent directories
- package-config - Get namespaced config from the closest package.json