# require-like

> Generates require functions that act as if they were operating in a given path.

Latest version **0.1.2** (published 2012-02-22) · 0 weekly downloads

## Install

```sh
npm install require-like
pnpm add require-like
yarn add require-like
bun add require-like
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.2 |
| Published | 2012-02-22 |
| First published | 2011-06-25 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Node | * |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 31 |
| Author | Felix Geisendörfer |
| Maintainers | felixge |

## Links

- npm: https://www.npmjs.com/package/require-like
- Repository: https://github.com/felixge/node-require-like
- npm.io page: https://npm.io/package/require-like

## Recent versions

- 0.1.2 (latest) — 2012-02-22
- 0.1.1 — 2011-11-20
- 0.1.0 — 2011-07-07
- 0.0.2 — 2011-06-25
- 0.0.1 — 2011-06-25

## README

# require-like

[![Build Status](https://secure.travis-ci.org/felixge/node-require-like.png)](http://travis-ci.org/felixge/node-require-like)

Generates require functions that act as if they were operating in a given path.

## Install

``` bash
npm install require-like
```

## Usage

A require function that acts as if it was executed in `'./lib/bar'`:

``` javascript
var requireLike = require('require-like');
var myRequire = requireLike(__dirname + '/lib/bar.js');

var myFoo = myRequire('./foo.js');
var foo = require('./lib/foo');

require('assert').strictEqual(myFoo, foo);
```

## API

### requireLike(path, [uncached])

Returns a require function that acts as if it was operating in the given
`path`.

Setting the `uncached` parameter to true returns a function that by-passes the
module cache.

## Implementation Details

This module works by accessing some private node APIs. You shouldn't worry about
that so, since I will make sure this module does not break in the future by
either patching it, or making a patch for node that makes the needed APIs
public.

## What to do with this

I use this library for dependency injection in unit tests. However, you could
also use it to create experimental require addons yourself.

## License

require-like is licensed under the MIT license.

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