3
implements the [node `require.resolve()`
4
algorithm](http://nodejs.org/docs/v0.4.8/api/all.html#all_Together...)
5
such that you can `require.resolve()` on behalf of a file asynchronously and
8
[![build status](https://secure.travis-ci.org/substack/node-resolve.png)](http://travis-ci.org/substack/node-resolve)
12
asynchronously resolve:
15
var resolve = require('resolve');
16
resolve('tap', { basedir: __dirname }, function (err, res) {
17
if (err) console.error(err)
23
$ node example/async.js
24
/home/substack/projects/node-resolve/node_modules/tap/lib/main.js
27
synchronously resolve:
30
var resolve = require('resolve');
31
var res = resolve.sync('tap', { basedir: __dirname });
36
$ node example/sync.js
37
/home/substack/projects/node-resolve/node_modules/tap/lib/main.js
43
var resolve = require('resolve')
46
## resolve(pkg, opts={}, cb)
48
Asynchronously resolve the module path string `pkg` into `cb(err, res)`.
52
* opts.basedir - directory to begin resolving from
54
* opts.extensions - array of file extensions to search in order
56
* opts.readFile - how to read files asynchronously
58
* opts.isFile - function to asynchronously test whether a file exists
60
* opts.packageFilter - transform the parsed package.json contents before looking
63
* opts.paths - require.paths array to use if nothing is found on the normal
64
node_modules recursive walk (probably don't use this)
66
default `opts` values:
72
extensions: [ '.js' ],
73
readFile: fs.readFile,
74
isFile: function (file, cb) {
75
fs.stat(file, function (err, stat) {
76
if (err && err.code === 'ENOENT') cb(null, false)
78
else cb(null, stat.isFile())
84
## resolve.sync(pkg, opts)
86
Synchronously resolve the module path string `pkg`, returning the result and
87
throwing an error when `pkg` can't be resolved.
91
* opts.basedir - directory to begin resolving from
93
* opts.extensions - array of file extensions to search in order
95
* opts.readFile - how to read files synchronously
97
* opts.isFile - function to synchronously test whether a file exists
99
* opts.packageFilter - transform the parsed package.json contents before looking
102
* opts.paths - require.paths array to use if nothing is found on the normal
103
node_modules recursive walk (probably don't use this)
105
default `opts` values:
111
extensions: [ '.js' ],
112
readFileSync: fs.readFileSync,
113
isFile: function (file) {
114
try { return fs.statSync(file).isFile() }
115
catch (e) { return false }
120
## resolve.isCore(pkg)
122
Return whether a package is in core.
126
With [npm](https://npmjs.org) do: