| hide_title | true |
|---|---|
| custom_edit_url | |
| pagination_prev | |
| pagination_next |
Home > @rushstack/node-core-library > PackageJsonLookup > loadOwnPackageJson
A helper for loading the caller's own package.json file.
Signature:
static loadOwnPackageJson(dirnameOfCaller: string): IPackageJson;|
Parameter |
Type |
Description |
|---|---|---|
|
dirnameOfCaller |
string |
The NodeJS |
Returns:
This function always returns a valid IPackageJson object. If any problems are encountered during loading, an exception will be thrown instead.
This function provides a concise and efficient way for an NPM package to report metadata about itself. For example, a tool might want to report its version.
The loadOwnPackageJson() probes upwards from the caller's folder, expecting to find a package.json file, which is assumed to be the caller's package. The result is cached, under the assumption that a tool's own package.json (and intermediary folders) will never change during the lifetime of the process.
// Report the version of our NPM package
const myPackageVersion: string = PackageJsonLookup.loadOwnPackageJson(__dirname).version;
console.log(`Cool Tool - Version ${myPackageVersion}`);