# req-cwd

> Require a module like `require()` but from the current working directory

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

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

## Install

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

## 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 | separate (@types/req-cwd) |
| Module format | CommonJS |
| Node | >=4 |
| Dependencies | 1 |
| Unpacked size | 3.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 52 |
| Author | Sindre Sorhus |
| Maintainers | sindresorhus |
| Keywords | require, resolve, path, module, from, like, cwd, current, working, directory, import |

## Links

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

## Dependencies (1)

- [req-from](https://npm.io/package/req-from.md) ^2.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-cwd [![Build Status](https://travis-ci.org/sindresorhus/req-cwd.svg?branch=master)](https://travis-ci.org/sindresorhus/req-cwd)

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


## Install

```
$ npm install --save req-cwd
```


## Usage

```js
const reqCwd = require('req-cwd');

// Target module is at '/Users/sindresorhus/unicorn/foo.js'

console.log(__dirname);
//=> '/Users/sindresorhus/rainbow'

console.log(process.cwd());
//=> '/Users/sindresorhus/unicorn'

const foo = reqCwd('./foo');
```


## API

### reqCwd(moduleId)

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

### reqCwd.silent(moduleId)

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

#### moduleId

Type: `string`

What you would use in `require()`.


## Related

- [req-from](https://github.com/sindresorhus/req-from) - Require a module from a given path
- [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-cwd · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
