findout

3.0.2 • Public • Published

findout

Build Status Code Climate Code Coverage npm Version JS Standard

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,

  1. require('foo')
  2. require('/bar/baz/foo')
  3. require('/bar/baz/node_modules/foo')
  4. require('/bar/foo')
  5. require('/bar/node_modules/foo')
  6. require('/foo')
  7. 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.

Readme

Keywords

Package Sidebar

Install

npm i findout

Weekly Downloads

2,662

Version

3.0.2

License

MIT

Unpacked Size

23.7 kB

Total Files

30

Last publish

Collaborators

  • okunishinishi