Find a file or directory by walking up parent directories
Installations
npm install find-up
Developer Guide
Typescript
Yes
Module System
ESM
Min. Node Version
>=18
Node Version
18.18.2
NPM Version
9.2.0
Score
99.4
Supply Chain
99
Quality
75.8
Maintenance
100
Vulnerability
100
License
Releases
Contributors
Unable to fetch Contributors
Languages
JavaScript (56.04%)
TypeScript (43.96%)
Developer
sindresorhus
Download Statistics
Total Downloads
25,134,118,021
Last Day
24,672,605
Last Week
112,550,927
Last Month
506,773,670
Last Year
6,543,462,751
GitHub Statistics
589 Stars
70 Commits
41 Forks
11 Watching
1 Branches
15 Contributors
Bundle Size
4.00 kB
Minified
1.56 kB
Minified + Gzipped
Sponsor this package
Package Meta Information
Latest Version
7.0.0
Package Id
find-up@7.0.0
Unpacked Size
16.10 kB
Size
3.79 kB
File Count
5
NPM Version
9.2.0
Node Version
18.18.2
Publised On
16 Nov 2023
Total Downloads
Cumulative downloads
Total Downloads
25,134,118,021
Last day
-5%
24,672,605
Compared to previous day
Last week
-15.4%
112,550,927
Compared to previous week
Last month
3.9%
506,773,670
Compared to previous month
Last year
9.9%
6,543,462,751
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dependencies
3
Dev Dependencies
5
find-up
Find a file or directory by walking up parent directories
Install
1npm install find-up
Usage
/
└── Users
└── sindresorhus
├── unicorn.png
└── foo
└── bar
├── baz
└── example.js
example.js
1import path from 'node:path'; 2import {findUp, pathExists} from 'find-up'; 3 4console.log(await findUp('unicorn.png')); 5//=> '/Users/sindresorhus/unicorn.png' 6 7console.log(await findUp(['rainbow.png', 'unicorn.png'])); 8//=> '/Users/sindresorhus/unicorn.png' 9 10console.log(await findUp(async directory => { 11 const hasUnicorns = await pathExists(path.join(directory, 'unicorn.png')); 12 return hasUnicorns && directory; 13}, {type: 'directory'})); 14//=> '/Users/sindresorhus'
API
findUp(name, options?)
findUp(matcher, options?)
Returns a Promise
for either the path or undefined
if it could not be found.
findUp([...name], options?)
Returns a Promise
for either the first path found (by respecting the order of the array) or undefined
if none could be found.
findUpMultiple(name, options?)
findUpMultiple(matcher, options?)
Returns a Promise
for either an array of paths or an empty array if none could be found.
findUpMultiple([...name], options?)
Returns a Promise
for either an array of the first paths found (by respecting the order of the array) or an empty array if none could be found.
findUpSync(name, options?)
findUpSync(matcher, options?)
Returns a path or undefined
if it could not be found.
findUpSync([...name], options?)
Returns the first path found (by respecting the order of the array) or undefined
if none could be found.
findUpMultipleSync(name, options?)
findUpMultipleSync(matcher, options?)
Returns an array of paths or an empty array if none could be found.
findUpMultipleSync([...name], options?)
Returns an array of the first paths found (by respecting the order of the array) or an empty array if none could be found.
name
Type: string
The name of the file or directory to find.
matcher
Type: Function
A function that will be called with each directory until it returns a string
with the path, which stops the search, or the root directory has been reached and nothing was found. Useful if you want to match files with certain patterns, set of permissions, or other advanced use-cases.
When using async mode, the matcher
may optionally be an async or promise-returning function that returns the path.
options
Type: object
cwd
Type: URL | string
Default: process.cwd()
The directory to start from.
type
Type: string
Default: 'file'
Values: 'file' | 'directory'
The type of path to match.
allowSymlinks
Type: boolean
Default: true
Allow symbolic links to match if they point to the chosen path type.
stopAt
Type: URL | string
Default: Root directory
A directory path where the search halts if no matches are found before reaching this point.
pathExists(path)
Returns a Promise<boolean>
of whether the path exists.
pathExistsSync(path)
Returns a boolean
of whether the path exists.
path
Type: string
The path to a file or directory.
findUpStop
A Symbol
that can be returned by a matcher
function to stop the search and cause findUp
to immediately return undefined
. Useful as a performance optimization in case the current working directory is deeply nested in the filesystem.
1import path from 'node:path'; 2import {findUp, findUpStop} from 'find-up'; 3 4await findUp(directory => { 5 return path.basename(directory) === 'work' ? findUpStop : 'logo.png'; 6});
Related
- find-up-cli - CLI for this module
- package-up - Find the closest package.json file
- pkg-dir - Find the root directory of an npm package
- resolve-from - Resolve the path of a module like
require.resolve()
but from a given path
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
security policy file detected
Details
- Info: security policy file detected: .github/security.md:1
- Info: Found linked content: .github/security.md:1
- Info: Found disclosure, vulnerability, and/or timelines in security policy: .github/security.md:1
- Info: Found text in security policy: .github/security.md:1
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
- Info: project has a license file: license:0
- Info: FSF or OSI recognized license: MIT License: license:0
Reason
Found 10/30 approved changesets -- score normalized to 3
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/main.yml:19: update your workflow using https://app.stepsecurity.io/secureworkflow/sindresorhus/find-up/main.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/main.yml:20: update your workflow using https://app.stepsecurity.io/secureworkflow/sindresorhus/find-up/main.yml/main?enable=pin
- Warn: npmCommand not pinned by hash: .github/workflows/main.yml:24
- Info: 0 out of 2 GitHub-owned GitHubAction dependencies pinned
- Info: 0 out of 1 npmCommand dependencies pinned
Reason
detected GitHub workflow tokens with excessive permissions
Details
- Warn: no topLevel permission defined: .github/workflows/main.yml:1
- Info: no jobLevel write permissions found
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'main'
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 10 are checked with a SAST tool
Score
4.3
/10
Last Scanned on 2025-01-27
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn MoreOther packages similar to find-up
read-pkg-up
Read the closest package.json file
pkg-up
Find the closest package.json file
pkg-dir
Find the root directory of a Node.js project or npm package
find-file-up
Find a file fast, by starting at the given cwd and recursing up one directory until the file is found or we run out of directories.