3 > Find the module object for something that was require()d
5 [![Build Status](https://travis-ci.org/nexdrew/which-module.svg?branch=master)](https://travis-ci.org/nexdrew/which-module)
6 [![Coverage Status](https://coveralls.io/repos/github/nexdrew/which-module/badge.svg?branch=master)](https://coveralls.io/github/nexdrew/which-module?branch=master)
7 [![Standard Version](https://img.shields.io/badge/release-standard%20version-brightgreen.svg)](https://github.com/conventional-changelog/standard-version)
9 Find the `module` object in `require.cache` for something that was `require()`d
10 or `import`ed - essentially a reverse `require()` lookup.
12 Useful for libs that want to e.g. lookup a filename for a module or submodule
13 that it did not `require()` itself.
18 npm install --save which-module
22 const whichModule = require('which-module')
24 console.log(whichModule(require('something')))
26 // id: '/path/to/project/node_modules/something/index.js',
27 // exports: [Function],
29 // filename: '/path/to/project/node_modules/something/index.js',
32 // paths: [ '/path/to/project/node_modules/something/node_modules',
33 // '/path/to/project/node_modules',
34 // '/path/to/node_modules',
35 // '/path/node_modules',
36 // '/node_modules' ] }
41 ### `whichModule(exported)`
43 Return the [`module` object](https://nodejs.org/api/modules.html#modules_the_module_object),
44 if any, that represents the given argument in the `require.cache`.
46 `exported` can be anything that was previously `require()`d or `import`ed as a
47 module, submodule, or dependency - which means `exported` is identical to the
48 `module.exports` returned by this method.
50 If `exported` did not come from the `exports` of a `module` in `require.cache`,
51 then this method returns `null`.