findout
v2.0.0 module require
findout
Find out a module.
Installation
npm install findout --save
Usage
findout(name)
works like require()
, but has a lot more locations to search.
'use strict'
const findout = require('findout')
// Resolve a module path.
let pathOfFoo = findout.resolve('foo')
// Find and require a module.
let foo = findout('foo', {
cwd: __dirname // Lookup from current directory.
})
How It Works
When you call findout
for "foo" with '/bar/baz' as current working directory:
findout('foo', {
cwd: '/bar/baz'
})
and it will try the following ways,
require('foo')
require('/bar/baz/foo')
require('/bar/baz/node_modules/foo')
require('/bar/foo')
require('/bar/node_modules/foo')
require('/foo')
require('/node_modules/foo')
If it still can't find any, throws an error.
Options
Key | Type | Default | Description |
---|---|---|---|
cwd | string | process.cwd() | Working directory path. |
safe | boolean | false | No throw when not found. |
License
This software is released under the MIT License.