require-me-maybe
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 = const file = processenvEXAMPLE_CONFIG_FILE // => this could throw // 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