Socket
Socket
Sign inDemoInstall

parent-package-json

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

parent-package-json

Find, read and parse the package.json of the parent module


Version published
Weekly downloads
5.4K
increased by6.73%
Maintainers
1
Weekly downloads
 
Created
Source

parent-package-json

Find, read and parse the package.json that sits above your module. Provide a custom ignore count or start path to define where to look for a parent package.

npm install --save parent-package-json
import parentJSON from "parent-package-json";

Getting Started

To get the nearest parent package.jsons path, content (as string) or parsed content (using JSON.parse):

const parent = parentJSON();

const pathToParentPackageJSON = parent.path.relative;
const parentContentAsString = parent.read();
const parentContentAsObject = parent.parse();

const parentVersion = parentContentAsObject.version;

The parent package.json is looked up starting from the current working directory of your script. If none is found, paths, .read() and .parse() will return undefined.

Custom Path and Ignore Count

If you need to determine the parent package.json of a custom path instead of the current working directory, which should be the module from which you are running the code, you can specify it via the path option:

const startPath = path.join(...);
const parent = parent({ startPath });

You can also specify a count of parent directories to skip:

const parent = parent({ ignoreCount: 1 });

Note: A package.json file in the provided startPath is always ignored. Set the startPath one layer below the one where you expect to find a parent package file.

Keywords

FAQs

Package last updated on 10 Jun 2023

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc