# require-or

> require, or...

Latest version **1.0.0** (published 2016-04-01) · ISC license · 0 weekly downloads

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

## Install

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

## Health

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

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2016-04-01 |
| First published | 2015-12-15 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Gustav Nikolaj |
| Maintainers | gustavnikolaj |
| Keywords | require, try, optional |

## Links

- npm: https://www.npmjs.com/package/require-or
- Repository: https://github.com/gustavnikolaj/require-or
- Homepage: https://github.com/gustavnikolaj/require-or#readme
- Issues: https://github.com/gustavnikolaj/require-or/issues
- npm.io page: https://npm.io/package/require-or

## Alternatives

- [@sentry/react-native](https://npm.io/package/@sentry/react-native.md) — 2.6M weekly downloads
- [@ardatan/aggregate-error](https://npm.io/package/@ardatan/aggregate-error.md) — 708.1K weekly downloads
- [custom-error-generator](https://npm.io/package/custom-error-generator.md) — 2.0K weekly downloads
- [@technik-sde/prosemirror-recreate-transform](https://npm.io/package/@technik-sde/prosemirror-recreate-transform.md) — 1.5K weekly downloads
- [@suchipi/error-utils](https://npm.io/package/@suchipi/error-utils.md) — 78 weekly downloads

## Recent versions

- 1.0.0 (latest) — 2016-04-01
- 0.0.2 — 2015-12-15
- 0.0.1 — 2015-12-15

## README

# require or ...

Converts:

```js
var someModule;
try {
    someModule = require('module-that-might-fail');
} catch (e) {
    console.log('AARGH! Could not find someModule!');
}
```

... into:

```js
var requireOr = require('require-or');
var someModule = requireOr('module-that-might-fail', function () {
    console.log('AARGH! Could not find someModule!');
});
```

The callback will be executed synchroniously and a return value
will be returned from requireOr as well, allowing:

```js
var someModule = requireOr('some-module', function () {
    return require('some-fallback-module');
});
```

The callback is not mandatory, so if you just want to squelch the
error message, you don't need to provide it:

```js
var maybeSomeModule = requireOr('some-module');
```

Relative paths works as well:

```js
var maybeSomeModule = requireOr('../some-module', function () {
    // ...
});
```

## Why?

There is multiple other modules trying to solve the same problem.

- [optional](https://github.com/tony-o/node-optional)
- [try-require](https://github.com/rragan/try-require)

Both solve the problem of squelching errors, but it does not give you any
improvements over vanilla require for the cases where you want to handle the
fall back case.

## License

This module is made public under the ISC License.

See the [LICENSE](https://github.com/gustavnikolaj/require-or/blob/master/LICENSE)
file for additional details.

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