require-me-maybe

1.0.2 • Public • Published

require-me-maybe Build Status NPM

A simple replacement for require with an optional fallback if the target module doesn't exist instead of throwing.

Install

npm install --save require-me-maybe

Usage

const requireMeMaybe = require('require-me-maybe')
const file = process.env.EXAMPLE_CONFIG_FILE

require(file) // => this could throw

requireMeMaybe(file, {
  // fallback defaults here
}) // this will never throw but rather return the fallback

API

requireMeMaybe(module, [defaults = { }])

Returns either the required module or the defaults. Defaults are returned if the desired module is undefined or not found.

Note that any other errors encountered while requiring the target module will still be thrown, including syntax errors.

License

MIT © Travis Fischer

Readme

Keywords

none

Package Sidebar

Install

npm i require-me-maybe

Weekly Downloads

0

Version

1.0.2

License

MIT

Last publish

Collaborators

  • fisch0920