pkg-dir

  • Version 8.0.0
  • Published
  • 4.93 kB
  • 1 dependency
  • MIT license

Install

npm i pkg-dir
yarn add pkg-dir
pnpm add pkg-dir

Overview

Find the root directory of a Node.js project or npm package

Index

Functions

function packageDirectory

packageDirectory: (options?: Options) => Promise<string | undefined>;
  • Find the root directory of a Node.js project or npm package.

    Returns

    The project root path or undefined if it could not be found.

    Example 1

    // /
    // └── Users
    // └── sindresorhus
    // └── foo
    // ├── package.json
    // └── bar
    // ├── baz
    // └── example.js
    // example.js
    import {packageDirectory} from 'pkg-dir';
    console.log(await packageDirectory());
    //=> '/Users/sindresorhus/foo'

function packageDirectorySync

packageDirectorySync: (options?: Options) => string | undefined;
  • Synchronously find the root directory of a Node.js project or npm package.

    Returns

    The project root path or undefined if it could not be found.

    Example 1

    // /
    // └── Users
    // └── sindresorhus
    // └── foo
    // ├── package.json
    // └── bar
    // ├── baz
    // └── example.js
    // example.js
    import {packageDirectorySync} from 'pkg-dir';
    console.log(packageDirectorySync());
    //=> '/Users/sindresorhus/foo'

Type Aliases

type Options

type Options = {
/**
The directory to start searching from.
@default process.cwd()
*/
readonly cwd?: string;
};

    Package Files (1)

    Dependencies (1)

    Dev Dependencies (4)

    Peer Dependencies (0)

    No peer dependencies.

    Badge

    To add a badge like this onejsDocs.io badgeto your package's README, use the codes available below.

    You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/pkg-dir.

    • Markdown
      [![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/pkg-dir)
    • HTML
      <a href="https://www.jsdocs.io/package/pkg-dir"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>