Need help with pkg-dir?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

sindresorhus
167 Stars 21 Forks MIT License 32 Commits 1 Opened issues

Description

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

Services available

!
?

Need anything else?

Contributors list

# 216
exec
test-fr...
nextjs
messeng...
21 commits
# 33,325
asteris...
exec
Babel
test-fr...
2 commits
# 5,527
TypeScr...
typescr...
iterm2
exec
2 commits
# 7,586
TypeScr...
vscode
exec
test-fr...
1 commit
# 7,970
ESLint
commiti...
semanti...
exec
1 commit
# 36,597
TypeScr...
lodash
CSS
html-we...
1 commit
# 6,551
chalk
exec
vuejs2
sketch-...
1 commit
# 1,998
bittorr...
html5
excel
XML
1 commit
# 22,722
Ember
fastboo...
Three.j...
ember-c...
1 commit

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.

Related

  • 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

Get professional support for this package with a Tidelift subscription
Tidelift helps make open source sustainable for maintainers while giving companies
assurances about security, maintenance, and licensing for their dependencies.

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.