\begin{quote}
Find a file or directory by walking up parent directories \end{quote}
\hypertarget{md_sfcode_node_modules_karma_node_modules_find_up_readme_autotoc_md14999}{}\doxysection{Install}\label{md_sfcode_node_modules_karma_node_modules_find_up_readme_autotoc_md14999}

\begin{DoxyCode}{0}
\DoxyCodeLine{\$ npm install find-\/up }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_karma_node_modules_find_up_readme_autotoc_md15000}{}\doxysection{Usage}\label{md_sfcode_node_modules_karma_node_modules_find_up_readme_autotoc_md15000}

\begin{DoxyCode}{0}
\DoxyCodeLine{/}
\DoxyCodeLine{└── Users}
\DoxyCodeLine{    └── sindresorhus}
\DoxyCodeLine{        ├── unicorn.png}
\DoxyCodeLine{        └── foo}
\DoxyCodeLine{            └── bar}
\DoxyCodeLine{                ├── baz}
\DoxyCodeLine{                └── example.js }

\end{DoxyCode}


{\ttfamily example.\+js}


\begin{DoxyCode}{0}
\DoxyCodeLine{const path = require('path');}
\DoxyCodeLine{const findUp = require('find-\/up');}
\DoxyCodeLine{}
\DoxyCodeLine{(async () => \{}
\DoxyCodeLine{    console.log(await findUp('unicorn.png'));}
\DoxyCodeLine{    //=> '/Users/sindresorhus/unicorn.png'}
\DoxyCodeLine{}
\DoxyCodeLine{    console.log(await findUp(['rainbow.png', 'unicorn.png']));}
\DoxyCodeLine{    //=> '/Users/sindresorhus/unicorn.png'}
\DoxyCodeLine{}
\DoxyCodeLine{    console.log(await findUp(async directory => \{}
\DoxyCodeLine{        const hasUnicorns = await findUp.exists(path.join(directory, 'unicorn.png'));}
\DoxyCodeLine{        return hasUnicorns \&\& directory;}
\DoxyCodeLine{    \}, \{type: 'directory'\}));}
\DoxyCodeLine{    //=> '/Users/sindresorhus'}
\DoxyCodeLine{\})(); }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_karma_node_modules_find_up_readme_autotoc_md15001}{}\doxysection{API}\label{md_sfcode_node_modules_karma_node_modules_find_up_readme_autotoc_md15001}
\hypertarget{md_sfcode_node_modules_karma_node_modules_find_up_readme_autotoc_md15002}{}\doxysubsection{find\+Up(name, options?)}\label{md_sfcode_node_modules_karma_node_modules_find_up_readme_autotoc_md15002}
\hypertarget{md_sfcode_node_modules_karma_node_modules_find_up_readme_autotoc_md15003}{}\doxysubsection{find\+Up(matcher, options?)}\label{md_sfcode_node_modules_karma_node_modules_find_up_readme_autotoc_md15003}
Returns a {\ttfamily Promise} for either the path or {\ttfamily undefined} if it couldn\textquotesingle{}t be found.\hypertarget{md_sfcode_node_modules_karma_node_modules_find_up_readme_autotoc_md15004}{}\doxysubsection{find\+Up(\mbox{[}...\+name\mbox{]}, options?)}\label{md_sfcode_node_modules_karma_node_modules_find_up_readme_autotoc_md15004}
Returns a {\ttfamily Promise} for either the first path found (by respecting the order of the array) or {\ttfamily undefined} if none could be found.\hypertarget{md_sfcode_node_modules_karma_node_modules_find_up_readme_autotoc_md15005}{}\doxysubsection{find\+Up.\+sync(name, options?)}\label{md_sfcode_node_modules_karma_node_modules_find_up_readme_autotoc_md15005}
\hypertarget{md_sfcode_node_modules_karma_node_modules_find_up_readme_autotoc_md15006}{}\doxysubsection{find\+Up.\+sync(matcher, options?)}\label{md_sfcode_node_modules_karma_node_modules_find_up_readme_autotoc_md15006}
Returns a path or {\ttfamily undefined} if it couldn\textquotesingle{}t be found.\hypertarget{md_sfcode_node_modules_karma_node_modules_find_up_readme_autotoc_md15007}{}\doxysubsection{find\+Up.\+sync(\mbox{[}...\+name\mbox{]}, options?)}\label{md_sfcode_node_modules_karma_node_modules_find_up_readme_autotoc_md15007}
Returns the first path found (by respecting the order of the array) or {\ttfamily undefined} if none could be found.\hypertarget{md_sfcode_node_modules_karma_node_modules_find_up_readme_autotoc_md15008}{}\doxysubsubsection{name}\label{md_sfcode_node_modules_karma_node_modules_find_up_readme_autotoc_md15008}
Type\+: {\ttfamily string}

Name of the file or directory to find.\hypertarget{md_sfcode_node_modules_karma_node_modules_find_up_readme_autotoc_md15009}{}\doxysubsubsection{matcher}\label{md_sfcode_node_modules_karma_node_modules_find_up_readme_autotoc_md15009}
Type\+: {\ttfamily Function}

A function that will be called with each directory until it returns a {\ttfamily 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 {\ttfamily matcher} may optionally be an async or promise-\/returning function that returns the path.\hypertarget{md_sfcode_node_modules_karma_node_modules_find_up_readme_autotoc_md15010}{}\doxysubsubsection{options}\label{md_sfcode_node_modules_karma_node_modules_find_up_readme_autotoc_md15010}
Type\+: {\ttfamily object}\hypertarget{md_sfcode_node_modules_karma_node_modules_find_up_readme_autotoc_md15011}{}\doxyparagraph{cwd}\label{md_sfcode_node_modules_karma_node_modules_find_up_readme_autotoc_md15011}
Type\+: {\ttfamily string}~\newline
 Default\+: {\ttfamily process.\+cwd()}

Directory to start from.\hypertarget{md_sfcode_node_modules_karma_node_modules_find_up_readme_autotoc_md15012}{}\doxyparagraph{type}\label{md_sfcode_node_modules_karma_node_modules_find_up_readme_autotoc_md15012}
Type\+: {\ttfamily string}~\newline
 Default\+: `\textquotesingle{}file'{\ttfamily $<$br$>$ Values\+:}\textquotesingle{}file\textquotesingle{}\textquotesingle{}directory\textquotesingle{}\`{}

The type of paths that can match.\hypertarget{md_sfcode_node_modules_karma_node_modules_find_up_readme_autotoc_md15013}{}\doxyparagraph{allow\+Symlinks}\label{md_sfcode_node_modules_karma_node_modules_find_up_readme_autotoc_md15013}
Type\+: {\ttfamily boolean}~\newline
 Default\+: {\ttfamily true}

Allow symbolic links to match if they point to the chosen path type.\hypertarget{md_sfcode_node_modules_karma_node_modules_find_up_readme_autotoc_md15014}{}\doxysubsection{find\+Up.\+exists(path)}\label{md_sfcode_node_modules_karma_node_modules_find_up_readme_autotoc_md15014}
Returns a {\ttfamily Promise$<$boolean$>$} of whether the path exists.\hypertarget{md_sfcode_node_modules_karma_node_modules_find_up_readme_autotoc_md15015}{}\doxysubsection{find\+Up.\+sync.\+exists(path)}\label{md_sfcode_node_modules_karma_node_modules_find_up_readme_autotoc_md15015}
Returns a {\ttfamily boolean} of whether the path exists.\hypertarget{md_sfcode_node_modules_karma_node_modules_find_up_readme_autotoc_md15016}{}\doxysubsubsection{path}\label{md_sfcode_node_modules_karma_node_modules_find_up_readme_autotoc_md15016}
Type\+: {\ttfamily string}

Path to a file or directory.\hypertarget{md_sfcode_node_modules_karma_node_modules_find_up_readme_autotoc_md15017}{}\doxysubsection{find\+Up.\+stop}\label{md_sfcode_node_modules_karma_node_modules_find_up_readme_autotoc_md15017}
A \href{https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol}{\texttt{ {\ttfamily Symbol}}} that can be returned by a {\ttfamily matcher} function to stop the search and cause {\ttfamily find\+Up} to immediately return {\ttfamily undefined}. Useful as a performance optimization in case the current working directory is deeply nested in the filesystem.


\begin{DoxyCode}{0}
\DoxyCodeLine{const path = require('path');}
\DoxyCodeLine{const findUp = require('find-\/up');}
\DoxyCodeLine{}
\DoxyCodeLine{(async () => \{}
\DoxyCodeLine{    await findUp(directory => \{}
\DoxyCodeLine{        return path.basename(directory) === 'work' ? findUp.stop : 'logo.png';}
\DoxyCodeLine{    \});}
\DoxyCodeLine{\})(); }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_karma_node_modules_find_up_readme_autotoc_md15018}{}\doxysection{Related}\label{md_sfcode_node_modules_karma_node_modules_find_up_readme_autotoc_md15018}

\begin{DoxyItemize}
\item \href{https://github.com/sindresorhus/find-up-cli}{\texttt{ find-\/up-\/cli}} -\/ CLI for this module
\item \href{https://github.com/sindresorhus/pkg-up}{\texttt{ pkg-\/up}} -\/ Find the closest package.\+json file
\item \href{https://github.com/sindresorhus/pkg-dir}{\texttt{ pkg-\/dir}} -\/ Find the root directory of an npm package
\item \href{https://github.com/sindresorhus/resolve-from}{\texttt{ resolve-\/from}} -\/ Resolve the path of a module like {\ttfamily require.\+resolve()} but from a given path
\end{DoxyItemize}

\DoxyHorRuler{0}


 {\bfseries{ \href{https://tidelift.com/subscription/pkg/npm-find-up?utm_source=npm-find-up&utm_medium=referral&utm_campaign=readme}{\texttt{ Get professional support for \textquotesingle{}find-\/up\textquotesingle{} with a Tidelift subscription}} }} ~\newline
 \textsubscript{ Tidelift helps make open source sustainable for maintainers while giving companies~\newline
assurances about security, maintenance, and licensing for their dependencies. }  