Dark Mode

Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

License

Notifications You must be signed in to change notification settings

sindresorhus/package-directory

Repository files navigation

package-directory

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

Install

npm install package-directory

Usage

/
+-- Users
+-- sindresorhus
+-- foo
+-- package.json
+-- bar
+-- baz
+-- example.js
'/Users/sindresorhus/foo'">// example.js
import {packageDirectory} from 'package-directory';

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.

ignoreTypeOnlyPackageJson

Type: boolean
Default: false

Ignore package.json files that only contain the type field.

This treats {"type":"module"} files as ESM scope markers instead of package roots.

Related

About

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

Resources

Readme

License

MIT license

Code of conduct

Code of conduct

Contributing

Contributing

Security policy

Security policy

Stars

Watchers

Forks

Packages

No packages published

Contributors 8