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

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

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

\begin{DoxyCode}{0}
\DoxyCodeLine{const importFrom = require('import-\/from');}
\DoxyCodeLine{}
\DoxyCodeLine{// There is a file at `./foo/bar.js`}
\DoxyCodeLine{}
\DoxyCodeLine{importFrom('foo', './bar'); }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_import_from_readme_autotoc_md12683}{}\doxysection{API}\label{md_sfcode_node_modules_import_from_readme_autotoc_md12683}
\hypertarget{md_sfcode_node_modules_import_from_readme_autotoc_md12684}{}\doxysubsection{import\+From(from\+Dir, module\+Id)}\label{md_sfcode_node_modules_import_from_readme_autotoc_md12684}
Like {\ttfamily require()}, throws when the module can\textquotesingle{}t be found.\hypertarget{md_sfcode_node_modules_import_from_readme_autotoc_md12685}{}\doxysubsection{import\+From.\+silent(from\+Dir, module\+Id)}\label{md_sfcode_node_modules_import_from_readme_autotoc_md12685}
Returns {\ttfamily null} instead of throwing when the module can\textquotesingle{}t be found.\hypertarget{md_sfcode_node_modules_import_from_readme_autotoc_md12686}{}\doxysubsubsection{from\+Dir}\label{md_sfcode_node_modules_import_from_readme_autotoc_md12686}
Type\+: {\ttfamily string}

Directory to import from.\hypertarget{md_sfcode_node_modules_import_from_readme_autotoc_md12687}{}\doxysubsubsection{module\+Id}\label{md_sfcode_node_modules_import_from_readme_autotoc_md12687}
Type\+: {\ttfamily string}

What you would use in {\ttfamily require()}.\hypertarget{md_sfcode_node_modules_import_from_readme_autotoc_md12688}{}\doxysection{Tip}\label{md_sfcode_node_modules_import_from_readme_autotoc_md12688}
Create a partial using a bound function if you want to import from the same {\ttfamily from\+Dir} multiple times\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{const importFromFoo = importFrom.bind(null, 'foo');}
\DoxyCodeLine{}
\DoxyCodeLine{importFromFoo('./bar');}
\DoxyCodeLine{importFromFoo('./baz'); }

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

\begin{DoxyItemize}
\item \href{https://github.com/sindresorhus/import-cwd}{\texttt{ import-\/cwd}} -\/ Import a module from the current working directory
\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_from_readme_autotoc_md12690}{}\doxysection{License}\label{md_sfcode_node_modules_import_from_readme_autotoc_md12690}
MIT © \href{https://sindresorhus.com}{\texttt{ Sindre Sorhus}} 