require-optional
v0.4.0
Published
Require optional modules
Downloads
1,329
Readme
require-optional
Usage
Install via npm:
$ npm install require-optional
Basic usage:
var requireOptional = require('require-optional')
var optDep = requireOptional('dep')
if (optDep) {
/* do stuff with optDep */
}
require-optional
can return a default value:
var optDep = requireOptional('dep', function () {})
optDep('processing')
require-optional
accepts an error callback for when the module is not found:
requireOptional('dep', null, function (err) {
console.warn(err)
})
require-optional
can also require relative modules:
var optDep = requireOptional('./dep')