pkg-dir

  • Version 6.0.1
  • Published
  • 5.34 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>;
  • 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;
  • 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'

Interfaces

interface Options

interface Options {}

    property cwd

    readonly cwd?: string;
    • The directory to start searching from.

      process.cwd()

    Package Files (1)

    Dependencies (1)

    Dev Dependencies (5)

    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>