\begin{quote}
Finds the common standard cache directory \end{quote}
The \href{https://github.com/istanbuljs/nyc}{\texttt{ {\ttfamily nyc}}} and \href{https://ava.li}{\texttt{ {\ttfamily AVA}}} projects decided to standardize on a common directory structure for storing cache information\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{\# nyc}
\DoxyCodeLine{./node\_modules/.cache/nyc}
\DoxyCodeLine{}
\DoxyCodeLine{\# ava}
\DoxyCodeLine{./node\_modules/.cache/ava}
\DoxyCodeLine{}
\DoxyCodeLine{\# your-\/module}
\DoxyCodeLine{./node\_modules/.cache/your-\/module }

\end{DoxyCode}


This module makes it easy to correctly locate the cache directory according to this shared spec. If this pattern becomes ubiquitous, clearing the cache for multiple dependencies becomes easy and consistent\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{rm -\/rf ./node\_modules/.cache }

\end{DoxyCode}


If you decide to adopt this pattern, please file a PR adding your name to the list of adopters below.\hypertarget{md_sfcode_node_modules_find_cache_dir_readme_autotoc_md10775}{}\doxysection{Install}\label{md_sfcode_node_modules_find_cache_dir_readme_autotoc_md10775}

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

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

\begin{DoxyCode}{0}
\DoxyCodeLine{const findCacheDir = require('find-\/cache-\/dir');}
\DoxyCodeLine{}
\DoxyCodeLine{findCacheDir(\{name: 'unicorns'\});}
\DoxyCodeLine{//=> '/user/path/node-\/modules/.cache/unicorns' }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_find_cache_dir_readme_autotoc_md10777}{}\doxysection{API}\label{md_sfcode_node_modules_find_cache_dir_readme_autotoc_md10777}
\hypertarget{md_sfcode_node_modules_find_cache_dir_readme_autotoc_md10778}{}\doxysubsection{find\+Cache\+Dir(options?)}\label{md_sfcode_node_modules_find_cache_dir_readme_autotoc_md10778}
Finds the cache directory using the supplied options. The algorithm checks for the {\ttfamily CACHE\+\_\+\+DIR} environmental variable and uses it if it is not set to {\ttfamily true}, {\ttfamily false}, {\ttfamily 1} or {\ttfamily 0}. If one is not found, it tries to find a {\ttfamily package.\+json} file, searching every parent directory of the {\ttfamily cwd} specified (or implied from other options). It returns a {\ttfamily string} containing the absolute path to the cache directory, or {\ttfamily undefined} if {\ttfamily package.\+json} was never found or if the {\ttfamily node\+\_\+modules} directory is unwritable.\hypertarget{md_sfcode_node_modules_find_cache_dir_readme_autotoc_md10779}{}\doxysubsubsection{options}\label{md_sfcode_node_modules_find_cache_dir_readme_autotoc_md10779}
Type\+: {\ttfamily object}\hypertarget{md_sfcode_node_modules_find_cache_dir_readme_autotoc_md10780}{}\doxyparagraph{name}\label{md_sfcode_node_modules_find_cache_dir_readme_autotoc_md10780}
{\itshape Required}\textbackslash{} Type\+: {\ttfamily string}

Should be the same as your project name in {\ttfamily package.\+json}.\hypertarget{md_sfcode_node_modules_find_cache_dir_readme_autotoc_md10781}{}\doxyparagraph{files}\label{md_sfcode_node_modules_find_cache_dir_readme_autotoc_md10781}
Type\+: {\ttfamily string\mbox{[}\mbox{]} $\vert$ string}

An array of files that will be searched for a common parent directory. This common parent directory will be used in lieu of the {\ttfamily cwd} option below.\hypertarget{md_sfcode_node_modules_find_cache_dir_readme_autotoc_md10782}{}\doxyparagraph{cwd}\label{md_sfcode_node_modules_find_cache_dir_readme_autotoc_md10782}
Type\+: {\ttfamily string}\textbackslash{} Default {\ttfamily process.\+cwd()}

Directory to start searching for a {\ttfamily package.\+json} from.\hypertarget{md_sfcode_node_modules_find_cache_dir_readme_autotoc_md10783}{}\doxyparagraph{create}\label{md_sfcode_node_modules_find_cache_dir_readme_autotoc_md10783}
Type\+: {\ttfamily boolean}\textbackslash{} Default {\ttfamily false}

If {\ttfamily true}, the directory will be created synchronously before returning.\hypertarget{md_sfcode_node_modules_find_cache_dir_readme_autotoc_md10784}{}\doxyparagraph{thunk}\label{md_sfcode_node_modules_find_cache_dir_readme_autotoc_md10784}
Type\+: {\ttfamily boolean}\textbackslash{} Default {\ttfamily false}

If {\ttfamily true}, this modifies the return type to be a function that is a thunk for {\ttfamily path.\+join(the\+Found\+Cache\+Directory)}.


\begin{DoxyCode}{0}
\DoxyCodeLine{const thunk = findCacheDir(\{name: 'foo', thunk: true\});}
\DoxyCodeLine{}
\DoxyCodeLine{thunk();}
\DoxyCodeLine{//=> '/some/path/node\_modules/.cache/foo'}
\DoxyCodeLine{}
\DoxyCodeLine{thunk('bar.js')}
\DoxyCodeLine{//=> '/some/path/node\_modules/.cache/foo/bar.js'}
\DoxyCodeLine{}
\DoxyCodeLine{thunk('baz', 'quz.js')}
\DoxyCodeLine{//=> '/some/path/node\_modules/.cache/foo/baz/quz.js' }

\end{DoxyCode}


This is helpful for actually putting actual files in the cache!\hypertarget{md_sfcode_node_modules_find_cache_dir_readme_autotoc_md10785}{}\doxysection{Tips}\label{md_sfcode_node_modules_find_cache_dir_readme_autotoc_md10785}

\begin{DoxyItemize}
\item To test modules using {\ttfamily find-\/cache-\/dir}, set the {\ttfamily CACHE\+\_\+\+DIR} environment variable to temporarily override the directory that is resolved.
\end{DoxyItemize}\hypertarget{md_sfcode_node_modules_find_cache_dir_readme_autotoc_md10786}{}\doxysection{Adopters}\label{md_sfcode_node_modules_find_cache_dir_readme_autotoc_md10786}

\begin{DoxyItemize}
\item \href{https://ava.li}{\texttt{ {\ttfamily AVA}}}
\item \href{https://github.com/istanbuljs/nyc}{\texttt{ {\ttfamily nyc}}}
\item \href{https://storybook.js.org}{\texttt{ {\ttfamily Storybook}}}
\item \href{https://github.com/babel/babel-loader}{\texttt{ {\ttfamily babel-\/loader}}}
\item \href{https://github.com/MoOx/eslint-loader}{\texttt{ {\ttfamily eslint-\/loader}}}
\item \href{https://phenomic.io}{\texttt{ {\ttfamily Phenomic}}}
\item \href{https://github.com/Beg-in/javascripthon-loader}{\texttt{ {\ttfamily javascripthon-\/loader}}}
\end{DoxyItemize}

\DoxyHorRuler{0}


 {\bfseries{ \href{https://tidelift.com/subscription/pkg/npm-find_cache-dir?utm_source=npm-find-cache-dir&utm_medium=referral&utm_campaign=readme}{\texttt{ Get professional support for this package 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. }  