\begin{quote}
Import a module like with \href{https://nodejs.org/api/globals.html\#globals_require}{\texttt{ {\ttfamily require()}}} but from the current working directory \end{quote}
\hypertarget{md_sfcode_node_modules_import_cwd_readme_autotoc_md12667}{}\doxysection{Install}\label{md_sfcode_node_modules_import_cwd_readme_autotoc_md12667}

\begin{DoxyCode}{0}
\DoxyCodeLine{\$ npm install -\/-\/save import-\/cwd }

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

\begin{DoxyCode}{0}
\DoxyCodeLine{const importCwd = require('import-\/cwd');}
\DoxyCodeLine{}
\DoxyCodeLine{// Target module is at '/Users/sindresorhus/unicorn/foo.js'}
\DoxyCodeLine{}
\DoxyCodeLine{console.log(\_\_dirname);}
\DoxyCodeLine{//=> '/Users/sindresorhus/rainbow'}
\DoxyCodeLine{}
\DoxyCodeLine{console.log(process.cwd());}
\DoxyCodeLine{//=> '/Users/sindresorhus/unicorn'}
\DoxyCodeLine{}
\DoxyCodeLine{const foo = importCwd('./foo'); }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_import_cwd_readme_autotoc_md12669}{}\doxysection{API}\label{md_sfcode_node_modules_import_cwd_readme_autotoc_md12669}
\hypertarget{md_sfcode_node_modules_import_cwd_readme_autotoc_md12670}{}\doxysubsection{import\+Cwd(module\+Id)}\label{md_sfcode_node_modules_import_cwd_readme_autotoc_md12670}
Like {\ttfamily require()}, throws when the module can\textquotesingle{}t be found.\hypertarget{md_sfcode_node_modules_import_cwd_readme_autotoc_md12671}{}\doxysubsection{import\+Cwd.\+silent(module\+Id)}\label{md_sfcode_node_modules_import_cwd_readme_autotoc_md12671}
Returns {\ttfamily null} instead of throwing when the module can\textquotesingle{}t be found.\hypertarget{md_sfcode_node_modules_import_cwd_readme_autotoc_md12672}{}\doxysubsubsection{module\+Id}\label{md_sfcode_node_modules_import_cwd_readme_autotoc_md12672}
Type\+: {\ttfamily string}

What you would use in {\ttfamily require()}.\hypertarget{md_sfcode_node_modules_import_cwd_readme_autotoc_md12673}{}\doxysection{Related}\label{md_sfcode_node_modules_import_cwd_readme_autotoc_md12673}

\begin{DoxyItemize}
\item \href{https://github.com/sindresorhus/import-from}{\texttt{ import-\/from}} -\/ Import a module from a given path
\item \href{https://github.com/sindresorhus/resolve-from}{\texttt{ resolve-\/from}} -\/ Resolve the path of a module from a given path
\item \href{https://github.com/sindresorhus/resolve-cwd}{\texttt{ resolve-\/cwd}} -\/ Resolve the path of a module from the current working directory
\item \href{https://github.com/sindresorhus/resolve-pkg}{\texttt{ resolve-\/pkg}} -\/ Resolve the path of a package regardless of it having an entry point
\item \href{https://github.com/sindresorhus/import-lazy}{\texttt{ import-\/lazy}} -\/ Import modules lazily
\end{DoxyItemize}\hypertarget{md_sfcode_node_modules_import_cwd_readme_autotoc_md12674}{}\doxysection{License}\label{md_sfcode_node_modules_import_cwd_readme_autotoc_md12674}
MIT © \href{https://sindresorhus.com}{\texttt{ Sindre Sorhus}} 