$ gnpm install read-pkg
Read a package.json file
npm install read-pkg
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<object>
with the parsed JSON.
Returns the parsed JSON.
Type: object
Type: URL | string
Default: process.cwd()
Current working directory.
Type: boolean
Default: true
Normalize the package data.
Parses an object or string into JSON.
Note: packageFile
is cloned using structuredClone
to prevent modification to the input object. This function is available from Node.js 18 on. In environments without structuredClone
(such as Node.js 16), a shallow spread is used instead, which can cause deep properties of the object to be modified. Consider cloning the object before using parsePackage
if that's the case.
Type: object | string
An object or a stringified object to be parsed as a package.json.
Type: object
Type: boolean
Default: true
Normalize the package data.
package.json
fileCopyright 2013 - present © cnpmjs.org | Home |