# req-from

> Require a module like `require()` but from a given path

Latest version **3.0.0** (published 2018-11-08) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install req-from
pnpm add req-from
yarn add req-from
bun add req-from
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 3.0.0 |
| Published | 2018-11-08 |
| First published | 2015-12-06 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=4 |
| Dependencies | 1 |
| Unpacked size | 3.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 85 |
| Author | Sindre Sorhus |
| Maintainers | sindresorhus |
| Keywords | require, resolve, path, module, from, like, import, path |

## Links

- npm: https://www.npmjs.com/package/req-from
- Repository: https://github.com/sindresorhus/req-from
- Homepage: https://github.com/sindresorhus/req-from#readme
- Issues: https://github.com/sindresorhus/req-from/issues
- npm.io page: https://npm.io/package/req-from

## Dependencies (1)

- [resolve-from](https://npm.io/package/resolve-from.md) ^3.0.0

## Alternatives

- [base64url](https://npm.io/package/base64url.md) — 6.1M weekly downloads
- [get-installed-path](https://npm.io/package/get-installed-path.md) — 502.9K weekly downloads
- [@uppy/url](https://npm.io/package/@uppy/url.md) — 185.8K weekly downloads
- [@d3fc/d3fc-shape](https://npm.io/package/@d3fc/d3fc-shape.md) — 16.2K weekly downloads
- [localizer](https://npm.io/package/localizer.md) — 226 weekly downloads

## Recent versions

- 3.0.0 (latest) — 2018-11-08
- 2.0.0 — 2017-04-28
- 1.0.1 — 2015-12-06
- 1.0.0 — 2015-12-06

## README

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

> Require a module like [`require()`](https://nodejs.org/api/globals.html#globals_require) but from a given path


## Install

```
$ npm install --save req-from
```


## Usage

```js
const reqFrom = require('req-from');

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

reqFrom('foo', './bar');
```


## API

### reqFrom(fromDir, moduleId)

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

### reqFrom.silent(fromDir, moduleId)

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

#### fromDir

Type: `string`

Directory to require from.

#### moduleId

Type: `string`

What you would use in `require()`.


## Tip

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

```js
const reqFromFoo = reqFrom.bind(null, 'foo');

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


## Related

- [req-cwd](https://github.com/sindresorhus/req-cwd) - Require a module from the current working directory
- [resolve-from](https://github.com/sindresorhus/resolve-from) - Resolve the path of a module from a given path
- [resolve-cwd](https://github.com/sindresorhus/resolve-cwd) - Resolve the path of 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)

---
_Source: https://npm.io/package/req-from · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
