Latest Threat Research:SANDWORM_MODE: Shai-Hulud-Style npm Worm Hijacks CI Workflows and Poisons AI Toolchains.Details
Socket
Book a DemoSign in
Socket

read-pkg

Package Overview
Dependencies
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

read-pkg

Read a package.json file

latest
Source
npmnpm
Version
10.1.0
Version published
Weekly downloads
39M
-14.08%
Maintainers
1
Weekly downloads
 
Created
Source

read-pkg

Read a package.json file

Why

  • Throws more helpful JSON errors
  • Normalizes the data

Install

npm install read-pkg

Usage

import {readPackage} from 'read-pkg';

console.log(await readPackage());
//=> {name: 'read-pkg', …}

console.log(await readPackage({cwd: 'some-other-directory'}));
//=> {name: 'unicorn', …}

API

readPackage(options?)

Returns a Promise<object> with the parsed JSON.

readPackageSync(options?)

Returns the parsed JSON.

options

Type: object

cwd

Type: URL | string
Default: process.cwd()

Current working directory.

normalize

Type: boolean
Default: true

Normalize the package data.

parsePackage(packageFile, options?)

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
Default: true

Normalize the package data.

Keywords

json

FAQs

Package last updated on 08 Feb 2026

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts