# which-module

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

Latest version **2.0.1** (published 2023-04-21) · ISC license · 0 weekly downloads

## Install

```sh
npm install which-module
pnpm add which-module
yarn add which-module
bun add which-module
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.1 |
| Published | 2023-04-21 |
| First published | 2016-06-06 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 3.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 27 |
| Author | nexdrew |
| Maintainers | nexdrew |
| Keywords | which, module, exports, filename, require, reverse, lookup |

## Links

- npm: https://www.npmjs.com/package/which-module
- Repository: https://github.com/nexdrew/which-module
- Homepage: https://github.com/nexdrew/which-module#readme
- Issues: https://github.com/nexdrew/which-module/issues
- npm.io page: https://npm.io/package/which-module

## Recent versions

- 2.0.1 (latest) — 2023-04-21
- 2.0.1-rc1 (rc) — 2023-04-21
- 2.0.0 — 2017-05-01
- 1.0.0 — 2016-06-06

## README

# which-module

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

[![Build Status](https://travis-ci.org/nexdrew/which-module.svg?branch=master)](https://travis-ci.org/nexdrew/which-module)
[![Coverage Status](https://coveralls.io/repos/github/nexdrew/which-module/badge.svg?branch=master)](https://coveralls.io/github/nexdrew/which-module?branch=master)
[![Standard Version](https://img.shields.io/badge/release-standard%20version-brightgreen.svg)](https://github.com/conventional-changelog/standard-version)
[![Greenkeeper badge](https://badges.greenkeeper.io/nexdrew/which-module.svg)](https://greenkeeper.io/)

Find the `module` object in `require.cache` for something that was `require()`d
or `import`ed - 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
```

```js
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](https://nodejs.org/api/modules.html#modules_the_module_object),
if any, that represents the given argument in the `require.cache`.

`exported` can be anything that was previously `require()`d or `import`ed 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

[opensourceregistry_package_id]: # (458260416784685e5ef3091fee54001785dd4360406aa3000315ff256eef6878)

---
_Source: https://npm.io/package/which-module · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
