Security News
JavaScript Leaders Demand Oracle Release the JavaScript Trademark
In an open letter, JavaScript community leaders urge Oracle to give up the JavaScript trademark, arguing that it has been effectively abandoned through nonuse.
parent-package-json
Advanced tools
Using parent-package-json, you can find the parent package.json
, so the package.json
of the module that uses your module.
npm install --save parent-package-json
var parent = require('parent-package-json');
For getting the path to the parent package.json
of the executing module (so the module that runs this code), simply do:
var pathToParent = parent().path;
If you're not sure if there's always a parent package.json, you can check first, too:
var pathToParent = parent(); // Will return false if no parent exists
if(pathToParent !== false) {
pathToParent = pathToParent.path;
}
Usually, parent-package-json
will use process.cwd()
for starting at, it will search the parent folders up until /
for finding a package.json
(and stops as soon as it finds one). If you want it to start somewhere other than process.cwd()
, provide a path as an argument instead:
var pathToParentOfCustomPath = parent('/My/Cool/Folder').path;
If you want to ignore a package.json
(for example to find the parent package.json
of the parent module), you can pass an
ignore parameter (default: 0) saying how many package.json
s you want to ignore when searching:
var pathToParentOfParent = parent(null, 1).path; // Or, even more complicated:
var pathToParentOfParentOfCustomPath = parent('/My/Cool/Folder', 1).path;
Note: The module's own package.json
is always ignored, even if the ignore parameter equals 0
parent-package-json
also allows you reading the content of a package.json
, and even parsing its JSON right away.
For reading its content, do:
var contentOfParent = parent().read();
If you want to parse its JSON code, you can run:
var JSONOfParent = parent().parse();
var versionOfParent = JSONOfParent.version;
// Or
var versionOfParent = parent().parse().version;
FAQs
Find, read and parse the package.json of the parent module
The npm package parent-package-json receives a total of 4,378 weekly downloads. As such, parent-package-json popularity was classified as popular.
We found that parent-package-json 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
In an open letter, JavaScript community leaders urge Oracle to give up the JavaScript trademark, arguing that it has been effectively abandoned through nonuse.
Security News
The initial version of the Socket Python SDK is now on PyPI, enabling developers to more easily interact with the Socket REST API in Python projects.
Security News
Floating dependency ranges in npm can introduce instability and security risks into your project by allowing unverified or incompatible versions to be installed automatically, leading to unpredictable behavior and potential conflicts.