0.0.5 • Published 7 years ago

require-grep v0.0.5

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

require-grep

Minimal NodeJS module finder with grepping capabilities.

In its simplest invocation this will return a list of paths (require() ready) that match the string, regexp or filter expression given.

var requireGrep = require('require-grep');

// Find the globally installed version of lodash
requireGrep('lodash', function(err, path) {
	// Path will be something like "/usr/lib/node_modules/lodash"
});

// Find all globally installed lodash plugins
requireGrep(^lodash-/, {multiple: true}, function(err, paths) {
	// Paths will be an array of found global module directories
});

Why

There are already quite a selection of modules that can find modules. But they have a variety of weird bugs, are unmaintained or rely on far too many weird-and-wonderful dependencies in order to do what is a relatively simple task - finding a module.

This module is intended to be as brain-dead as possible - doing only one single thing - returning a list of modules matching a grep.

Options

OptionDefaultDescription
callbackthe last argumentThe callback to invoke with (err, foundPath) parameters
grepsthe first argumentAn array of grep expressions to search by. These can be strings, regExps or functions
localtrueSearch the local directory for modules
globalfalseSearch all global paths for modules
globalPathsprocess.env.NODE_PATHThe global paths to search
localPaths./node_modulesThe local paths to search
multiplefalseShortcut property to set {failNone: false, failOne: false, failMultiple: false, array: true}
failNonetrueReturn an error if no modules were found
failOnefalseReturn an error if only one module was found
failMultipletrueReturn an error if multiple modules were found
failDirErrfalseReturn an error if any of the module search paths raise an error. False will fail silently (recommended)
failDirStatfalseReturn an error if any of the module search paths fail to stat. False will fail silently (recommended)
failDirJSONfalseReturn an error if any of the candidate modules do not have a valid JSON file. False will fail silently (recommended)