Product
Introducing License Enforcement in Socket
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
fd-package-json
Advanced tools
Finds the closest package.json
and returns the path or the contents.
npm i -S fd-package-json
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
MIT
FAQs
Utilities for finding the closest package.json file
We found that fd-package-json demonstrated a healthy version release cadence and project activity because the last version was released less than 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.
Product
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
Product
We're launching a new set of license analysis and compliance features for analyzing, managing, and complying with licenses across a range of supported languages and ecosystems.
Product
We're excited to introduce Socket Optimize, a powerful CLI command to secure open source dependencies with tested, optimized package overrides.