pkg-up
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|---|---|---|---|---|
find-up | 3.0.0 | 2.22 kB | MIT | prod |
"Pkg-up" is a useful npm package that assists developers in finding the nearest package.json file within a directory or file structure. By using an efficient up-tree search algorithm, it locates the closest package.json, starting its search from the current working directory (process.cwd() by default) or any directory specified by the user.
The utilization of "pkg-up" is straightforward and conveniently done within your JavaScript environment. To begin, install the package into your project using npm install pkg-up
. Following a successful installation, you then import the package into your JavaScript file with import {pkgUp} from 'pkg-up';
. By executing console.log(await pkgUp());
, the closest package.json file path relative to your current working directory will be logged to your console as a string. In instances where the package.json file cannot be found, the promise will resolve to undefined. The package also provides a synchronous method, pkgUpSync(options), which follows the same process but without returning a promise. Here is an example of its usage:
// Import pkg-up
import {pkgUp} from 'pkg-up';
// Use pkg-up to find and print the path of the closest package.json file
console.log(await pkgUp());
// This could possibly print out: '/Users/sindresorhus/foo/package.json'
The pkgUp()
and pkgUpSync()
methods both accept an optional object parameter that allows you to specify the "cwd" (current working directory) from where the search should commence.
The official documentation for "pkg-up" is available within the readme content on its GitHub repository page at https://github.com/sindresorhus/pkg-up. You'll find a detailed breakdown of its API, including usage examples and the options available for customizing the package's behavior.