Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

read-pkg-up

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

read-pkg-up

Read the closest package.json file

  • 11.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created

What is read-pkg-up?

The read-pkg-up npm package is used to read the nearest package.json file in a directory tree. It starts from the specified directory and searches upwards for a package.json file, then parses it and returns the result. This can be useful for Node.js projects that need to access metadata about themselves or their dependencies.

What are read-pkg-up's main functionalities?

Read the closest package.json

This feature allows you to asynchronously read the nearest package.json file from the current directory and log its contents and the path where it was found.

const readPkgUp = require('read-pkg-up');

(async () => {
  const { packageJson, path } = await readPkgUp();
  console.log(packageJson);
  console.log(`Found at ${path}`);
})();

Synchronous reading of package.json

This feature provides a synchronous method to read the nearest package.json file and log its contents and the path where it was found.

const readPkgUp = require('read-pkg-up');

const { packageJson, path } = readPkgUp.sync();
console.log(packageJson);
console.log(`Found at ${path}`);

Custom starting directory

This feature allows you to specify a custom starting directory when searching for the package.json file.

const readPkgUp = require('read-pkg-up');

(async () => {
  const { packageJson, path } = await readPkgUp({ cwd: 'some/subdirectory' });
  console.log(packageJson);
  console.log(`Found at ${path}`);
})();

Other packages similar to read-pkg-up

Keywords

FAQs

Package last updated on 03 Nov 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