which-module

2.0.1 • Public • Published

which-module

Find the module object for something that was require()d

Build Status Coverage Status Standard Version Greenkeeper badge

Find the module object in require.cache for something that was require()d or imported - essentially a reverse require() lookup.

Useful for libs that want to e.g. lookup a filename for a module or submodule that it did not require() itself.

Install and Usage

npm install --save which-module
const whichModule = require('which-module')

console.log(whichModule(require('something')))
// Module {
//   id: '/path/to/project/node_modules/something/index.js',
//   exports: [Function],
//   parent: ...,
//   filename: '/path/to/project/node_modules/something/index.js',
//   loaded: true,
//   children: [],
//   paths: [ '/path/to/project/node_modules/something/node_modules',
//            '/path/to/project/node_modules',
//            '/path/to/node_modules',
//            '/path/node_modules',
//            '/node_modules' ] }

API

whichModule(exported)

Return the module object, if any, that represents the given argument in the require.cache.

exported can be anything that was previously require()d or imported as a module, submodule, or dependency - which means exported is identical to the module.exports returned by this method.

If exported did not come from the exports of a module in require.cache, then this method returns null.

License

ISC © Contributors

Versions

Current Tags

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 2.0.1
    9,243,190
  • 2.0.1-rc1
    181
  • 2.0.0
    7,515,368
  • 1.0.0
    1,960,442

Package Sidebar

Install

npm i which-module

Weekly Downloads

18,719,181

Version

2.0.1

License

ISC

Unpacked Size

4.04 kB

Total Files

4

Last publish

Collaborators

  • nexdrew