Node.js filesystem utility

@stackline/find-parent-dir

Find the nearest parent containing a file or directory. Keep the established callback and sync API, or use native ESM and Promise support with correct filesystem errors.

npm install @stackline/find-parent-dir
v1.0.0 zero runtime dependencies Node.js 12-24 TypeScript 3.9+

Executable example builder

Traversal planner

Distinct candidate paths

nearest first

Generated program

Traversal plan ready

Compatibility boundary

Textual traversal stays textual.

The supplied path is checked first, then reduced one path part at a time. Results retain upstream separators and symlink aliases; the implementation does not call realpath or normalize the returned directory.

findParentDir(start, clue, callback)
findParentDir.sync(start, clue)
findParentDir.promise(start, clue)

ENOENT and ENOTDIR continue traversal. Access denial, symlink loops, and other filesystem errors stop at the failing boundary and retain the original error object.

Read the complete compatibility contract

Public surface

Three APIs, one traversal contract

APIResultErrorAvailability
findParentDir(start, clue, cb)cb(null, directory | null)cb(error)Historical
findParentDir.sync(start, clue)string | nullthrowsHistorical
findParentDir.promise(start, clue)Promise<string | null>rejectsAdditive

Release evidence

Compatibility is measured.

The release gate checks behavior, package shape, compiler boundaries, platforms, and the installed artifact.

600
differential path searches against the frozen upstream release
100%
core statements, branches, functions, and lines
3 OS
Linux, macOS, and Windows filesystem behavior in CI
0
runtime dependencies in the published package

Drop-in adoption

Keep existing imports.

Use an npm alias when changing application source is not desirable. The installed implementation is Stackline while the dependency key remains find-parent-dir.

npm install find-parent-dir@npm:@stackline/find-parent-dir
Open the migration guide

Inspect the release

Source, package, license, and machine-readable docs