Socket
Socket
Sign inDemoInstall

fd-package-json

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fd-package-json

Utilities for finding the closest package.json file


Version published
Weekly downloads
885K
decreased by-8.33%
Maintainers
1
Weekly downloads
 
Created
Source

fd-package-json

Finds the closest package.json and returns the path or the contents.

Install

npm i -S fd-package-json

Usage

To retrieve the path of the closest package, you can use findPackagePath:

import {findPackagePath} from 'fd-package-json';

// Closest package path to cwd of the process
await findPackagePath(process.cwd());

// Closest package path to the current file (CJS)
await findPackagePath(__dirname);

// Closest package path to the current file (ESM)
await findPackagePath(fileURLToPath(new URL('.', import.meta.url)));

To retrieve the package itself, you may use findPackage with the same parameter:

await findPackage(process.cwd()); // Returns the JSON of the package if found

Synchronous methods also exist:

findPackageSync(process.cwd()); // returns the package

findPackagePathSync(process.cwd()); // returns the package path

License

MIT

Keywords

FAQs

Package last updated on 18 Jun 2024

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