\begin{quote}
Find the root directory of a Node.\+js project or npm package \end{quote}
\hypertarget{md_sfcode_node_modules_pkg_dir_readme_autotoc_md20422}{}\doxysection{Install}\label{md_sfcode_node_modules_pkg_dir_readme_autotoc_md20422}

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

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

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

\end{DoxyCode}



\begin{DoxyCode}{0}
\DoxyCodeLine{// example.js}
\DoxyCodeLine{const pkgDir = require('pkg-\/dir');}
\DoxyCodeLine{}
\DoxyCodeLine{(async () => \{}
\DoxyCodeLine{    const rootDir = await pkgDir(\_\_dirname);}
\DoxyCodeLine{}
\DoxyCodeLine{    console.log(rootDir);}
\DoxyCodeLine{    //=> '/Users/sindresorhus/foo'}
\DoxyCodeLine{\})(); }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_pkg_dir_readme_autotoc_md20424}{}\doxysection{API}\label{md_sfcode_node_modules_pkg_dir_readme_autotoc_md20424}
\hypertarget{md_sfcode_node_modules_pkg_dir_readme_autotoc_md20425}{}\doxysubsection{pkg\+Dir(\mbox{[}cwd\mbox{]})}\label{md_sfcode_node_modules_pkg_dir_readme_autotoc_md20425}
Returns a {\ttfamily Promise} for either the project root path or {\ttfamily null} if it couldn\textquotesingle{}t be found.\hypertarget{md_sfcode_node_modules_pkg_dir_readme_autotoc_md20426}{}\doxysubsection{pkg\+Dir.\+sync(\mbox{[}cwd\mbox{]})}\label{md_sfcode_node_modules_pkg_dir_readme_autotoc_md20426}
Returns the project root path or {\ttfamily null}.\hypertarget{md_sfcode_node_modules_pkg_dir_readme_autotoc_md20427}{}\doxysubsubsection{cwd}\label{md_sfcode_node_modules_pkg_dir_readme_autotoc_md20427}
Type\+: {\ttfamily string}~\newline
 Default\+: {\ttfamily process.\+cwd()}

Directory to start from.\hypertarget{md_sfcode_node_modules_pkg_dir_readme_autotoc_md20428}{}\doxysection{Related}\label{md_sfcode_node_modules_pkg_dir_readme_autotoc_md20428}

\begin{DoxyItemize}
\item \href{https://github.com/sindresorhus/pkg-dir-cli}{\texttt{ pkg-\/dir-\/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/find-up}{\texttt{ find-\/up}} -\/ Find a file by walking up parent directories
\end{DoxyItemize}\hypertarget{md_sfcode_node_modules_pkg_dir_readme_autotoc_md20429}{}\doxysection{License}\label{md_sfcode_node_modules_pkg_dir_readme_autotoc_md20429}
MIT © \href{https://sindresorhus.com}{\texttt{ Sindre Sorhus}} 