Open-Awesome
CategoriesAlternativesStacksSelf-HostedExplore
Open-Awesome

© 2026 Open-Awesome. Curated for the developer elite.

TermsPrivacyAboutGitHubRSS
  1. Home
  2. Node.js
  3. package-directory

package-directory

MITJavaScriptv8.2.0

Find the root directory of a Node.js project or npm package by walking up from a given directory.

GitHubGitHub
253 stars21 forks0 contributors

What is package-directory?

package-directory is a Node.js library that finds the root directory of a Node.js project or npm package by searching for a `package.json` file while walking up the directory tree. It solves the problem of tools needing to reliably locate the project context from any subdirectory, which is crucial for configuration, path resolution, and build automation.

Target Audience

Node.js developers and tool authors who need to programmatically determine the project root for scripts, CLIs, build tools, or development utilities.

Value Proposition

Developers choose package-directory for its simplicity, reliability, and seamless integration with the Node.js ecosystem. It provides both async and sync APIs with configurable options, making it a robust solution compared to manual directory traversal.

Overview

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

Use Cases

Best For

  • Building CLI tools that need to locate project configuration files
  • Writing build scripts that require the project root for path resolution
  • Developing IDE extensions or linters that operate within a project context
  • Creating development utilities that automate tasks based on project structure
  • Integrating with other file-finding libraries like `find-up` or `package-up`
  • Handling edge cases in monorepos or projects with ESM configuration

Not Ideal For

  • Projects that define root directories with files other than package.json (e.g., .git, composer.json for PHP)
  • Applications running in environments without file system access, like browser-based tools or serverless functions with restricted I/O
  • Monorepos where tools need to detect multiple package.json files without stopping at the first valid root
  • Teams requiring built-in caching for repeated directory lookups to avoid performance overhead

Pros & Cons

Pros

Accurate Root Detection

Reliably locates the project root by searching for package.json, with an option to ignore files containing only a type field, ensuring correct handling of ESM scopes as per the README.

Flexible API Design

Provides both Promise-based async (packageDirectory) and synchronous (packageDirectorySync) functions, making it adaptable to different Node.js coding styles and use cases.

Configurable Search Options

Allows setting a custom starting directory (cwd) and toggling ignoreTypeOnlyPackageJson, offering control over edge cases in modern project setups as documented in the API.

Ecosystem Integration

Designed to work seamlessly with related utilities like package-up and find-up, enhancing its utility in toolchains and build processes, as noted in the README's Related section.

Cons

Single File Dependency

Solely relies on package.json for detection, so it fails in projects without this file or those using alternative root markers, limiting its universality.

No Multi-Root Support

Stops at the first valid package.json encountered, making it unsuitable for tools that need to identify all package roots in nested monorepo structures.

Synchronous Performance Risk

The sync API can block the event loop when walking up deep directory trees, which may impact performance in I/O-heavy or real-time applications.

Frequently Asked Questions

Quick Stats

Stars253
Forks21
Contributors0
Open Issues0
Last commit5 months ago
CreatedSince 2015

Tags

#directory-traversal#package-json#build-tools#npm-package#nodejs#file-system

Built With

N
Node.js

Included in

Node.js65.5k
Auto-fetched 15 hours ago

Related Projects

chokidarchokidar

Minimal and efficient cross-platform file watching library

Stars12,188
Forks630
Last commit2 days ago
fs-extrafs-extra

Node.js: extra methods for the fs object like copy(), remove(), mkdirs()

Stars9,604
Forks785
Last commit22 hours ago
globbyglobby

User-friendly glob matching

Stars2,647
Forks137
Last commit8 days ago
deldel

Delete files and directories

Stars1,345
Forks69
Last commit3 days ago
Community-curated · Updated weekly · 100% open source

Found a gem we're missing?

Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.

Submit a projectStar on GitHub