1.0.2 • Published 8 years ago
require-me-maybe v1.0.2
require-me-maybe

A simple replacement for
requirewith an optional fallback if the target module doesn't exist instead of throwing.
Install
npm install --save require-me-maybeUsage
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 fallbackAPI
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
