Sha256: fa992a4a03bf205cb8348530ff7cdccfb1e5773f58c6d7e9ad8d1a69cd643c90

Contents?: true

Size: 1.67 KB

Versions: 35

Compression:

Stored size: 1.67 KB

Contents

# resolve-from [![Build Status](https://travis-ci.org/sindresorhus/resolve-from.svg?branch=master)](https://travis-ci.org/sindresorhus/resolve-from)

> Resolve the path of a module like [`require.resolve()`](https://nodejs.org/api/globals.html#globals_require_resolve) but from a given path


## Install

```
$ npm install --save resolve-from
```


## Usage

```js
const resolveFrom = require('resolve-from');

// There is a file at `./foo/bar.js`

resolveFrom('foo', './bar');
//=> '/Users/sindresorhus/dev/test/foo/bar.js'
```


## API

### resolveFrom(fromDir, moduleId)

Like `require()`, throws when the module can't be found.

### resolveFrom.silent(fromDir, moduleId)

Returns `null` instead of throwing when the module can't be found.

#### fromDir

Type: `string`

Directory to resolve from.

#### moduleId

Type: `string`

What you would use in `require()`.


## Tip

Create a partial using a bound function if you want to resolve from the same `fromDir` multiple times:

```js
const resolveFromFoo = resolveFrom.bind(null, 'foo');

resolveFromFoo('./bar');
resolveFromFoo('./baz');
```


## Related

- [resolve-cwd](https://github.com/sindresorhus/resolve-cwd) - Resolve the path of a module from the current working directory
- [req-from](https://github.com/sindresorhus/req-from) - Require a module from a given path
- [req-cwd](https://github.com/sindresorhus/req-cwd) - Require a module from the current working directory
- [resolve-pkg](https://github.com/sindresorhus/resolve-pkg) - Resolve the path of a package regardless of it having an entry point
- [lazy-req](https://github.com/sindresorhus/lazy-req) - Require modules lazily


## License

MIT © [Sindre Sorhus](https://sindresorhus.com)

Version data entries

35 entries across 34 versions & 12 rubygems

Version Path
optimacms-0.1.61 spec/dummy/node_modules/resolve-from/readme.md
disco_app-0.18.0 test/dummy/node_modules/resolve-from/readme.md
disco_app-0.18.2 test/dummy/node_modules/resolve-from/readme.md
disco_app-0.16.1 test/dummy/node_modules/resolve-from/readme.md
disco_app-0.15.2 test/dummy/node_modules/resolve-from/readme.md
disco_app-0.18.4 test/dummy/node_modules/resolve-from/readme.md
disco_app-0.18.1 test/dummy/node_modules/resolve-from/readme.md
disco_app-0.12.7.pre.puma.pre.3 test/dummy/node_modules/resolve-from/readme.md
disco_app-0.14.0 test/dummy/node_modules/resolve-from/readme.md
disco_app-0.13.6.pre.puma.pre.3 test/dummy/node_modules/resolve-from/readme.md
tang-0.2.1 spec/tang_app/node_modules/resolve-from/readme.md
groonga-client-model-6.0.0 test/apps/rails6.1.3/node_modules/resolve-from/readme.md
groonga-client-model-6.0.0 test/apps/rails6.0.3.5/node_modules/resolve-from/readme.md
ruby2js-4.0.4 lib/tasks/testrails/node_modules/resolve-from/readme.md
ruby2js-4.0.3 lib/tasks/testrails/node_modules/resolve-from/readme.md
tang-0.2.0 spec/tang_app/node_modules/resolve-from/readme.md
tang-0.1.0 spec/tang_app/node_modules/resolve-from/readme.md
tang-0.0.9 spec/tang_app/node_modules/resolve-from/readme.md
enju_library-0.3.8 spec/dummy/node_modules/resolve-from/readme.md
ilog-0.4.1 node_modules/resolve-from/readme.md