require-optional

Require optional modules

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
require-optional
300.4.06 years ago8 years agoMinified + gzip package size for require-optional in KB

Readme

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')