1.0.2 • Published 7 years ago

require-me-maybe v1.0.2

Weekly downloads
4
License
MIT
Repository
github
Last release
7 years ago

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

npm.io