read-pkg
Advanced tools
Weekly downloads
Readme
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
fileFAQs
Read a package.json file
The npm package read-pkg receives a total of 31,022,320 weekly downloads. As such, read-pkg popularity was classified as popular.
We found that read-pkg demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket installs a Github app to automatically flag issues on every pull request and report the health of your dependencies. Find out what is inside your node modules and prevent malicious activity before you update the dependencies.