
Security News
Google’s OSV Fix Just Added 500+ New Advisories — All Thanks to One Small Policy Change
A data handling bug in OSV.dev caused disputed CVEs to disappear from vulnerability feeds until a recent fix restored over 500 advisories.
An easy way to expose properties on a module from a package.json
npm install pkginfo
How often when writing node.js modules have you written the following line(s) of code?
exports.version = '0.1.0';
exports.version = require('/path/to/package.json').version;
In other words, how often have you wanted to expose basic information from your package.json onto your module programmatically? WELL NOW YOU CAN!
Using pkginfo
is idiot-proof, just require and invoke it.
var pkginfo = require('pkginfo')(module);
console.dir(module.exports);
By invoking the pkginfo
module all of the properties in your package.json
file will be automatically exposed on the callee module (i.e. the parent module of pkginfo
).
Here's a sample of the output:
{ name: 'simple-app',
description: 'A test fixture for pkginfo',
version: '0.1.0',
author: 'Charlie Robbins <charlie.robbins@gmail.com>',
keywords: [ 'test', 'fixture' ],
main: './index.js',
scripts: { test: 'vows test/*-test.js --spec' },
engines: { node: '>= 0.4.0' } }
If you don't want to expose all properties on from your package.json
on your module then simple pass those properties to the pkginfo
function:
var pkginfo = require('pkginfo')(module, 'version', 'author');
console.dir(module.exports);
{ version: '0.1.0',
author: 'Charlie Robbins <charlie.robbins@gmail.com>' }
If you're looking for further usage see the examples included in this repository.
Tests are written in vows and give complete coverage of all APIs.
npm install
npm test
The 'read-pkg' package reads the package.json file and returns its content as a JavaScript object. Unlike 'pkginfo', which attaches the information to the module.exports object, 'read-pkg' provides a more straightforward way to access the package.json content directly.
The 'pkg-up' package finds the closest package.json file by traversing up from the current directory. It is useful for locating the package.json file in a project, whereas 'pkginfo' focuses on retrieving information from a known package.json file.
The 'normalize-package-data' package normalizes package metadata, ensuring that the package.json data conforms to expected standards. While 'pkginfo' retrieves package information, 'normalize-package-data' focuses on validating and cleaning the data.
FAQs
An easy way to expose properties on a module from a package.json
The npm package pkginfo receives a total of 1,438,267 weekly downloads. As such, pkginfo popularity was classified as popular.
We found that pkginfo 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.
Security News
A data handling bug in OSV.dev caused disputed CVEs to disappear from vulnerability feeds until a recent fix restored over 500 advisories.
Research
/Security News
175 malicious npm packages (26k+ downloads) used unpkg CDN to host redirect scripts for a credential-phishing campaign targeting 135+ organizations worldwide.
Security News
Python 3.14 adds template strings, deferred annotations, and subinterpreters, plus free-threaded mode, an experimental JIT, and Sigstore verification.