pkg-dir
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|---|---|---|---|---|
find-up-simple | 1.0.0 | 2.54 kB | MIT | prod |
Pkg-dir is a beneficial npm package that aims at finding the root directory of a Node.js project or npm package.
You can use pkg-dir by installing it first in your Node.js project using the npm package manager with the command npm install pkg-dir
. After successful installation, you can import it in your Javascript file and use its functions like packageDirectory
or packageDirectorySync
. The packageDirectory
function returns a promise for the project root path. In case, it can't find the path, a return value of undefined
will be given. For instance:
// Import the module
import {packageDirectory} from 'pkg-dir';
// Use the function packageDirectory to get the root path
console.log(await packageDirectory());
If you want to use the synchronous version, you can make use of packageDirectorySync
.
Additionally, you can specify the directory to start searching from by passing an options object with 'cwd' property set to your desired directory.
The pkg-dir documentations are available on its GitHub page at https://github.com/sindresorhus/pkg-dir. The documentation provides detailed information including installation, usage, and API references along with examples. Moreover, it also recommends related packages that might be of interest. For professional support, they advise getting a Tidelift subscription.