1. pkg-dir
Find the root directory of a Node.js project or npm package
pkg-dir
Package: pkg-dir
Created by: sindresorhus
Last modified: Fri, 03 Nov 2023 20:02:47 GMT
Version: 8.0.0
License: MIT
Downloads: 253,595,909
Repository: https://github.com/sindresorhus/pkg-dir

Install

npm install pkg-dir
yarn add pkg-dir

pkg-dir

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

Install

 npm install pkg-dir

Usage

/
└── Users
    └── sindresorhus
        └── foo
            ├── package.json
            └── bar
                ├── baz
                └── example.js
 // example.js
import {packageDirectory} from 'pkg-dir';

console.log(await packageDirectory());
//=> '/Users/sindresorhus/foo'

API

packageDirectory(option?)

Returns a Promise for either the project root path or undefined if it could not be found.

packageDirectorySync(options?)

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

options

Type: object

cwd

Type: string
Default: process.cwd()

The directory to start searching from.

  • pkg-dir-cli - CLI for this module
  • pkg-up - Find the closest package.json file
  • find-up - Find a file by walking up parent directories

RELATED POST

10 Must-Know Windows Shortcuts That Will Save You Time

10 Must-Know Windows Shortcuts That Will Save You Time

Arrays vs Linked Lists: Which is Better for Memory Management in Data Structures?

Arrays vs Linked Lists: Which is Better for Memory Management in Data Structures?

Navigating AWS Networking: Essential Hacks for Smooth Operation

Navigating AWS Networking: Essential Hacks for Smooth Operation

Achieving Stunning Visuals with Unity's Global Illumination

Achieving Stunning Visuals with Unity's Global Illumination

Nim's Hidden Gems: Lesser-known Features for Writing Efficient Code

Nim's Hidden Gems: Lesser-known Features for Writing Efficient Code