read-package-json
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|---|---|---|---|---|
glob | 10.3.10 | 66.83 kB | ISC | prod | 2 2 |
json-parse-even-better-errors | 3.0.1 | 4.34 kB | MIT | prod | |
normalize-package-data | 5.0.0 | 8.66 kB | BSD-2-Clause | prod | 1 2 |
npm-normalize-package-bin | 3.0.1 | 1.8 kB | ISC | prod |
Read-package-json is a handy npm package that brings a collection of functionalities to handle package.json files. This module is majorly used by npm and unravels package.json files with enhanced semantics, validation, and default values. Notably, it cache files that have been read to prevent reading the same file more than once. Also, it validates certain elements, and provides defaults where necessary. Furthermore, the package comes with a feature that allows you to see your project the same way npm will see it.
To use the read-package-json npm package, you need to install it in your project first. Once the package is successfully installed, you can require and use it in your JavaScript file. Here's a basic usage example:
var readJson = require('read-package-json')
// readJson(filename, [logFunction=noop], [strict=false], cb)
readJson('/path/to/package.json', console.error, false, function (er, data) {
if (er) {
console.error("There was an error reading the file")
return
}
console.error('the package data is', data)
});
The readJson function accepts four parameters: the filename (file path for the package.json file), a logging function (defaults to noop), a Boolean value (strict) to specify if SemVer 2.0 version strings and other strict requirements should be enforced, and a callback function that gets called with (er, data)
.
Read-package-json's documentation and details can be found directly in the readme section of the project's GitHub repository (https://github.com/npm/read-package-json.git). The documentation includes fields and usage details alongside numerous specific functions related to this package and other pertinent information.