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';
await findPackagePath(process.cwd());
await findPackagePath(__dirname);
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());
Synchronous methods also exist:
findPackageSync(process.cwd());
findPackagePathSync(process.cwd());
License
MIT