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

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

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

\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_protractor_node_modules_find_up_readme_autotoc_md22758}{}\doxysection{API}\label{md_sfcode_node_modules_protractor_node_modules_find_up_readme_autotoc_md22758}
\hypertarget{md_sfcode_node_modules_protractor_node_modules_find_up_readme_autotoc_md22759}{}\doxysubsection{find\+Up(name, options?)}\label{md_sfcode_node_modules_protractor_node_modules_find_up_readme_autotoc_md22759}
\hypertarget{md_sfcode_node_modules_protractor_node_modules_find_up_readme_autotoc_md22760}{}\doxysubsection{find\+Up(matcher, options?)}\label{md_sfcode_node_modules_protractor_node_modules_find_up_readme_autotoc_md22760}
Returns a {\ttfamily Promise} for either the path or {\ttfamily undefined} if it couldn\textquotesingle{}t be found.\hypertarget{md_sfcode_node_modules_protractor_node_modules_find_up_readme_autotoc_md22761}{}\doxysubsection{find\+Up(\mbox{[}...\+name\mbox{]}, options?)}\label{md_sfcode_node_modules_protractor_node_modules_find_up_readme_autotoc_md22761}
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_protractor_node_modules_find_up_readme_autotoc_md22762}{}\doxysubsection{find\+Up.\+sync(name, options?)}\label{md_sfcode_node_modules_protractor_node_modules_find_up_readme_autotoc_md22762}
\hypertarget{md_sfcode_node_modules_protractor_node_modules_find_up_readme_autotoc_md22763}{}\doxysubsection{find\+Up.\+sync(matcher, options?)}\label{md_sfcode_node_modules_protractor_node_modules_find_up_readme_autotoc_md22763}
Returns a path or {\ttfamily undefined} if it couldn\textquotesingle{}t be found.\hypertarget{md_sfcode_node_modules_protractor_node_modules_find_up_readme_autotoc_md22764}{}\doxysubsection{find\+Up.\+sync(\mbox{[}...\+name\mbox{]}, options?)}\label{md_sfcode_node_modules_protractor_node_modules_find_up_readme_autotoc_md22764}
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_protractor_node_modules_find_up_readme_autotoc_md22765}{}\doxysubsubsection{name}\label{md_sfcode_node_modules_protractor_node_modules_find_up_readme_autotoc_md22765}
Type\+: {\ttfamily string}

Name of the file or directory to find.\hypertarget{md_sfcode_node_modules_protractor_node_modules_find_up_readme_autotoc_md22766}{}\doxysubsubsection{matcher}\label{md_sfcode_node_modules_protractor_node_modules_find_up_readme_autotoc_md22766}
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_protractor_node_modules_find_up_readme_autotoc_md22767}{}\doxysubsubsection{options}\label{md_sfcode_node_modules_protractor_node_modules_find_up_readme_autotoc_md22767}
Type\+: {\ttfamily object}\hypertarget{md_sfcode_node_modules_protractor_node_modules_find_up_readme_autotoc_md22768}{}\doxyparagraph{cwd}\label{md_sfcode_node_modules_protractor_node_modules_find_up_readme_autotoc_md22768}
Type\+: {\ttfamily string}~\newline
 Default\+: {\ttfamily process.\+cwd()}

Directory to start from.\hypertarget{md_sfcode_node_modules_protractor_node_modules_find_up_readme_autotoc_md22769}{}\doxyparagraph{type}\label{md_sfcode_node_modules_protractor_node_modules_find_up_readme_autotoc_md22769}
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_protractor_node_modules_find_up_readme_autotoc_md22770}{}\doxyparagraph{allow\+Symlinks}\label{md_sfcode_node_modules_protractor_node_modules_find_up_readme_autotoc_md22770}
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_protractor_node_modules_find_up_readme_autotoc_md22771}{}\doxysubsection{find\+Up.\+exists(path)}\label{md_sfcode_node_modules_protractor_node_modules_find_up_readme_autotoc_md22771}
Returns a {\ttfamily Promise$<$boolean$>$} of whether the path exists.\hypertarget{md_sfcode_node_modules_protractor_node_modules_find_up_readme_autotoc_md22772}{}\doxysubsection{find\+Up.\+sync.\+exists(path)}\label{md_sfcode_node_modules_protractor_node_modules_find_up_readme_autotoc_md22772}
Returns a {\ttfamily boolean} of whether the path exists.\hypertarget{md_sfcode_node_modules_protractor_node_modules_find_up_readme_autotoc_md22773}{}\doxysubsubsection{path}\label{md_sfcode_node_modules_protractor_node_modules_find_up_readme_autotoc_md22773}
Type\+: {\ttfamily string}

Path to a file or directory.\hypertarget{md_sfcode_node_modules_protractor_node_modules_find_up_readme_autotoc_md22774}{}\doxysubsection{find\+Up.\+stop}\label{md_sfcode_node_modules_protractor_node_modules_find_up_readme_autotoc_md22774}
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_protractor_node_modules_find_up_readme_autotoc_md22775}{}\doxysection{Related}\label{md_sfcode_node_modules_protractor_node_modules_find_up_readme_autotoc_md22775}

\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. }  