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 = // Resolve a module path.let pathOfFoo = findout // Find and require a module.let foo =
How It Works
When you call findout
for "foo" with '/bar/baz' as current working directory:
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.