Research
Security News
Malicious npm Package Targets Solana Developers and Hijacks Funds
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
The read-pkg npm package is used to read a package.json file and parse its contents. It can normalize the data according to the npm normalization rules, handle different file encodings, and can read from different locations by resolving the path to the nearest package.json file.
Read package.json from the current directory
This feature reads the package.json file from the current working directory and outputs the parsed JSON object.
const readPkg = require('read-pkg');
(async () => {
const pkg = await readPkg();
console.log(pkg);
})();
Read package.json from a specified directory
This feature allows you to specify a directory from which to read the package.json file, rather than the current working directory.
const readPkg = require('read-pkg');
(async () => {
const pkg = await readPkg({ cwd: 'path/to/directory' });
console.log(pkg);
})();
Read and normalize package.json data
This feature reads the package.json file and normalizes its data according to npm normalization rules, which can be useful for ensuring consistent data structure.
const readPkg = require('read-pkg');
(async () => {
const pkg = await readPkg({ normalize: true });
console.log(pkg);
})();
read-package-json is an npm package that reads the package.json file and also provides normalization. It is the library that npm itself uses to read package.json files, which means it's well-tested and reliable, but it might be more complex and tightly coupled with npm's internal use cases compared to read-pkg.
load-json-file is a package that provides a simple API for reading and parsing JSON files. It does not specifically target package.json files, so it lacks the normalization features of read-pkg, but it can be used for general JSON file reading purposes.
pkg-conf is a package that reads configuration from package.json files. It's focused on retrieving configuration settings rather than reading the entire package.json file, so it serves a slightly different purpose compared to 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.
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 41,552,850 weekly downloads. As such, read-pkg popularity was classified as popular.
We found that read-pkg demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.