implements the \href{https://nodejs.org/api/modules.html\#modules_all_together}{\texttt{ node {\ttfamily require.\+resolve()} algorithm}} such that you can {\ttfamily require.\+resolve()} on behalf of a file asynchronously and synchronously

\href{http://travis-ci.org/browserify/resolve}{\texttt{ }}\hypertarget{md_sfcode_node_modules_resolve_readme_autotoc_md24370}{}\doxysection{example}\label{md_sfcode_node_modules_resolve_readme_autotoc_md24370}
asynchronously resolve\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{var resolve = require('resolve');}
\DoxyCodeLine{resolve('tap', \{ basedir: \_\_dirname \}, function (err, res) \{}
\DoxyCodeLine{    if (err) console.error(err);}
\DoxyCodeLine{    else console.log(res);}
\DoxyCodeLine{\}); }

\end{DoxyCode}



\begin{DoxyCode}{0}
\DoxyCodeLine{\$ node example/async.js}
\DoxyCodeLine{/home/substack/projects/node-\/resolve/node\_modules/tap/lib/main.js }

\end{DoxyCode}


synchronously resolve\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{var resolve = require('resolve');}
\DoxyCodeLine{var res = resolve.sync('tap', \{ basedir: \_\_dirname \});}
\DoxyCodeLine{console.log(res); }

\end{DoxyCode}



\begin{DoxyCode}{0}
\DoxyCodeLine{\$ node example/sync.js}
\DoxyCodeLine{/home/substack/projects/node-\/resolve/node\_modules/tap/lib/main.js }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_resolve_readme_autotoc_md24371}{}\doxysection{methods}\label{md_sfcode_node_modules_resolve_readme_autotoc_md24371}

\begin{DoxyCode}{0}
\DoxyCodeLine{var resolve = require('resolve'); }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_resolve_readme_autotoc_md24372}{}\doxysubsection{resolve(id, opts=\{\}, cb)}\label{md_sfcode_node_modules_resolve_readme_autotoc_md24372}
Asynchronously resolve the module path string {\ttfamily id} into {\ttfamily cb(err, res \mbox{[}, pkg\mbox{]})}, where {\ttfamily pkg} (if defined) is the data from {\ttfamily package.\+json}.

options are\+:


\begin{DoxyItemize}
\item opts.\+basedir -\/ directory to begin resolving from
\item opts.\+package -\/ {\ttfamily package.\+json} data applicable to the module being loaded
\item opts.\+extensions -\/ array of file extensions to search in order
\item opts.\+read\+File -\/ how to read files asynchronously
\item opts.\+is\+File -\/ function to asynchronously test whether a file exists
\item opts.\+is\+Directory -\/ function to asynchronously test whether a directory exists
\item opts.\+realpath -\/ function to asynchronously resolve a potential symlink to its real path
\item {\ttfamily opts.\+package\+Filter(pkg, pkgfile, dir)} -\/ transform the parsed package.\+json contents before looking at the \char`\"{}main\char`\"{} field
\begin{DoxyItemize}
\item pkg -\/ package data
\item pkgfile -\/ path to package.\+json
\item dir -\/ directory for package.\+json
\end{DoxyItemize}
\item {\ttfamily opts.\+path\+Filter(pkg, path, relative\+Path)} -\/ transform a path within a package
\begin{DoxyItemize}
\item pkg -\/ package data
\item path -\/ the path being resolved
\item relative\+Path -\/ the path relative from the package.\+json location
\item returns -\/ a relative path that will be joined from the package.\+json location
\end{DoxyItemize}
\item opts.\+paths -\/ require.\+paths array to use if nothing is found on the normal {\ttfamily node\+\_\+modules} recursive walk (probably don\textquotesingle{}t use this)

For advanced users, {\ttfamily paths} can also be a {\ttfamily opts.\+paths(request, start, opts)} function
\begin{DoxyItemize}
\item request -\/ the import specifier being resolved
\item start -\/ lookup path
\item get\+Node\+Modules\+Dirs -\/ a thunk (no-\/argument function) that returns the paths using standard {\ttfamily node\+\_\+modules} resolution
\item opts -\/ the resolution options
\end{DoxyItemize}
\item {\ttfamily opts.\+package\+Iterator(request, start, opts)} -\/ return the list of candidate paths where the packages sources may be found (probably don\textquotesingle{}t use this)
\begin{DoxyItemize}
\item request -\/ the import specifier being resolved
\item start -\/ lookup path
\item get\+Package\+Candidates -\/ a thunk (no-\/argument function) that returns the paths using standard {\ttfamily node\+\_\+modules} resolution
\item opts -\/ the resolution options
\end{DoxyItemize}
\item opts.\+module\+Directory -\/ directory (or directories) in which to recursively look for modules. default\+: {\ttfamily \char`\"{}node\+\_\+modules\char`\"{}}
\item opts.\+preserve\+Symlinks -\/ if true, doesn\textquotesingle{}t resolve {\ttfamily basedir} to real path before resolving. This is the way Node resolves dependencies when executed with the \href{https://nodejs.org/api/all.html\#cli_preserve_symlinks}{\texttt{ --preserve-\/symlinks}} flag. {\bfseries{Note\+:}} this property is currently {\ttfamily true} by default but it will be changed to {\ttfamily false} in the next major version because {\itshape Node\textquotesingle{}s resolution algorithm does not preserve symlinks by default}.
\end{DoxyItemize}

default {\ttfamily opts} values\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{\{}
\DoxyCodeLine{    paths: [],}
\DoxyCodeLine{    basedir: \_\_dirname,}
\DoxyCodeLine{    extensions: ['.js'],}
\DoxyCodeLine{    readFile: fs.readFile,}
\DoxyCodeLine{    isFile: function isFile(file, cb) \{}
\DoxyCodeLine{        fs.stat(file, function (err, stat) \{}
\DoxyCodeLine{            if (!err) \{}
\DoxyCodeLine{                return cb(null, stat.isFile() || stat.isFIFO());}
\DoxyCodeLine{            \}}
\DoxyCodeLine{            if (err.code === 'ENOENT' || err.code === 'ENOTDIR') return cb(null, false);}
\DoxyCodeLine{            return cb(err);}
\DoxyCodeLine{        \});}
\DoxyCodeLine{    \},}
\DoxyCodeLine{    isDirectory: function isDirectory(dir, cb) \{}
\DoxyCodeLine{        fs.stat(dir, function (err, stat) \{}
\DoxyCodeLine{            if (!err) \{}
\DoxyCodeLine{                return cb(null, stat.isDirectory());}
\DoxyCodeLine{            \}}
\DoxyCodeLine{            if (err.code === 'ENOENT' || err.code === 'ENOTDIR') return cb(null, false);}
\DoxyCodeLine{            return cb(err);}
\DoxyCodeLine{        \});}
\DoxyCodeLine{    \},}
\DoxyCodeLine{    realpath: function realpath(file, cb) \{}
\DoxyCodeLine{        var realpath = typeof fs.realpath.native === 'function' ? fs.realpath.native : fs.realpath;}
\DoxyCodeLine{        realpath(file, function (realPathErr, realPath) \{}
\DoxyCodeLine{            if (realPathErr \&\& realPathErr.code !== 'ENOENT') cb(realPathErr);}
\DoxyCodeLine{            else cb(null, realPathErr ? file : realPath);}
\DoxyCodeLine{        \});}
\DoxyCodeLine{    \},}
\DoxyCodeLine{    moduleDirectory: 'node\_modules',}
\DoxyCodeLine{    preserveSymlinks: true}
\DoxyCodeLine{\} }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_resolve_readme_autotoc_md24373}{}\doxysubsection{resolve.\+sync(id, opts)}\label{md_sfcode_node_modules_resolve_readme_autotoc_md24373}
Synchronously resolve the module path string {\ttfamily id}, returning the result and throwing an error when {\ttfamily id} can\textquotesingle{}t be resolved.

options are\+:


\begin{DoxyItemize}
\item opts.\+basedir -\/ directory to begin resolving from
\item opts.\+extensions -\/ array of file extensions to search in order
\item opts.\+read\+File -\/ how to read files synchronously
\item opts.\+is\+File -\/ function to synchronously test whether a file exists
\item opts.\+is\+Directory -\/ function to synchronously test whether a directory exists
\item opts.\+realpath\+Sync -\/ function to synchronously resolve a potential symlink to its real path
\item {\ttfamily opts.\+package\+Filter(pkg, dir)} -\/ transform the parsed package.\+json contents before looking at the \char`\"{}main\char`\"{} field
\begin{DoxyItemize}
\item pkg -\/ package data
\item dir -\/ directory for package.\+json (Note\+: the second argument will change to \char`\"{}pkgfile\char`\"{} in v2)
\end{DoxyItemize}
\item {\ttfamily opts.\+path\+Filter(pkg, path, relative\+Path)} -\/ transform a path within a package
\begin{DoxyItemize}
\item pkg -\/ package data
\item path -\/ the path being resolved
\item relative\+Path -\/ the path relative from the package.\+json location
\item returns -\/ a relative path that will be joined from the package.\+json location
\end{DoxyItemize}
\item opts.\+paths -\/ require.\+paths array to use if nothing is found on the normal {\ttfamily node\+\_\+modules} recursive walk (probably don\textquotesingle{}t use this)

For advanced users, {\ttfamily paths} can also be a {\ttfamily opts.\+paths(request, start, opts)} function
\begin{DoxyItemize}
\item request -\/ the import specifier being resolved
\item start -\/ lookup path
\item get\+Node\+Modules\+Dirs -\/ a thunk (no-\/argument function) that returns the paths using standard {\ttfamily node\+\_\+modules} resolution
\item opts -\/ the resolution options
\end{DoxyItemize}
\item {\ttfamily opts.\+package\+Iterator(request, start, opts)} -\/ return the list of candidate paths where the packages sources may be found (probably don\textquotesingle{}t use this)
\begin{DoxyItemize}
\item request -\/ the import specifier being resolved
\item start -\/ lookup path
\item get\+Package\+Candidates -\/ a thunk (no-\/argument function) that returns the paths using standard {\ttfamily node\+\_\+modules} resolution
\item opts -\/ the resolution options
\end{DoxyItemize}
\item opts.\+module\+Directory -\/ directory (or directories) in which to recursively look for modules. default\+: {\ttfamily \char`\"{}node\+\_\+modules\char`\"{}}
\item opts.\+preserve\+Symlinks -\/ if true, doesn\textquotesingle{}t resolve {\ttfamily basedir} to real path before resolving. This is the way Node resolves dependencies when executed with the \href{https://nodejs.org/api/all.html\#cli_preserve_symlinks}{\texttt{ --preserve-\/symlinks}} flag. {\bfseries{Note\+:}} this property is currently {\ttfamily true} by default but it will be changed to {\ttfamily false} in the next major version because {\itshape Node\textquotesingle{}s resolution algorithm does not preserve symlinks by default}.
\end{DoxyItemize}

default {\ttfamily opts} values\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{\{}
\DoxyCodeLine{    paths: [],}
\DoxyCodeLine{    basedir: \_\_dirname,}
\DoxyCodeLine{    extensions: ['.js'],}
\DoxyCodeLine{    readFileSync: fs.readFileSync,}
\DoxyCodeLine{    isFile: function isFile(file) \{}
\DoxyCodeLine{        try \{}
\DoxyCodeLine{            var stat = fs.statSync(file);}
\DoxyCodeLine{        \} catch (e) \{}
\DoxyCodeLine{            if (e \&\& (e.code === 'ENOENT' || e.code === 'ENOTDIR')) return false;}
\DoxyCodeLine{            throw e;}
\DoxyCodeLine{        \}}
\DoxyCodeLine{        return stat.isFile() || stat.isFIFO();}
\DoxyCodeLine{    \},}
\DoxyCodeLine{    isDirectory: function isDirectory(dir) \{}
\DoxyCodeLine{        try \{}
\DoxyCodeLine{            var stat = fs.statSync(dir);}
\DoxyCodeLine{        \} catch (e) \{}
\DoxyCodeLine{            if (e \&\& (e.code === 'ENOENT' || e.code === 'ENOTDIR')) return false;}
\DoxyCodeLine{            throw e;}
\DoxyCodeLine{        \}}
\DoxyCodeLine{        return stat.isDirectory();}
\DoxyCodeLine{    \},}
\DoxyCodeLine{    realpathSync: function realpathSync(file) \{}
\DoxyCodeLine{        try \{}
\DoxyCodeLine{            var realpath = typeof fs.realpathSync.native === 'function' ? fs.realpathSync.native : fs.realpathSync;}
\DoxyCodeLine{            return realpath(file);}
\DoxyCodeLine{        \} catch (realPathErr) \{}
\DoxyCodeLine{            if (realPathErr.code !== 'ENOENT') \{}
\DoxyCodeLine{                throw realPathErr;}
\DoxyCodeLine{            \}}
\DoxyCodeLine{        \}}
\DoxyCodeLine{        return file;}
\DoxyCodeLine{    \},}
\DoxyCodeLine{    moduleDirectory: 'node\_modules',}
\DoxyCodeLine{    preserveSymlinks: true}
\DoxyCodeLine{\} }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_resolve_readme_autotoc_md24374}{}\doxysection{install}\label{md_sfcode_node_modules_resolve_readme_autotoc_md24374}
With \href{https://npmjs.org}{\texttt{ npm}} do\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{npm install resolve }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_resolve_readme_autotoc_md24375}{}\doxysection{license}\label{md_sfcode_node_modules_resolve_readme_autotoc_md24375}
MIT 