npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@stackline/find-parent-dir

v1.0.0

Published

Find the nearest parent containing a file or directory with callback, sync, and Promise APIs

Downloads

101

Readme

@stackline/find-parent-dir

CI npm license

Find the nearest parent directory containing a file or directory. This is a maintained, zero-dependency continuation of [email protected] with the historical callback and synchronous APIs plus Promise, ESM, and first-party TypeScript support.

Install

npm install @stackline/find-parent-dir

Existing source imports can stay unchanged with an npm alias:

npm install find-parent-dir@npm:@stackline/find-parent-dir

Usage

Callback

const findParentDir = require('@stackline/find-parent-dir')

findParentDir(__dirname, 'package.json', (error, directory) => {
  if (error) throw error
  console.log(directory) // nearest directory, or null
})

Synchronous

const findParentDir = require('@stackline/find-parent-dir')

const directory = findParentDir.sync(__dirname, '.git')

Promise and ESM

import { promise as findParentDir } from '@stackline/find-parent-dir'

const directory = await findParentDir(import.meta.dirname, 'package.json')

The default ESM export exposes the same .sync and .promise methods as the CommonJS function.

Compatibility

The established contract is preserved:

  • traversal starts at the exact supplied path and moves toward its textual parent without resolving symlinks;
  • the first directory containing clue is returned;
  • missing paths and ENOTDIR candidates continue traversal;
  • no match returns null;
  • path separators and trailing separators follow the upstream behavior;
  • callback and synchronous function arity remain unchanged;
  • index and index.js deep imports remain available.

One correctness fix is intentional: access and filesystem errors such as EACCES, EPERM, and ELOOP are delivered to the callback, thrown by .sync, or reject .promise. Upstream used fs.exists*, which converted those errors to false and could silently continue above an inaccessible boundary.

See COMPATIBILITY_CONTRACT.md and MIGRATION.md for the complete boundary.

API

findParentDir(start, clue, callback)

Search asynchronously. callback(error, directory) receives the nearest matching directory or null.

findParentDir.sync(start, clue)

Search synchronously. Returns the nearest matching directory or null, and throws non-missing filesystem errors.

findParentDir.promise(start, clue)

Search asynchronously and return Promise<string | null>. This method is additive and does not change the historical APIs.

Support

  • Node.js 12 through 24 are tested.
  • CommonJS and native ESM are tested.
  • TypeScript 3.9 and the current compiler are tested.
  • Linux, macOS, and Windows are covered in CI.
  • There are no runtime dependencies.

Project documents

License and attribution

MIT. The original copyright notice for Thorsten Lorenz is preserved in LICENSE. This project is an independent maintained continuation and is not affiliated with or endorsed by the original author.