Socket
Socket
Sign inDemoInstall

which-module

Package Overview
Dependencies
0
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

which-module

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


Version published
Maintainers
1
Weekly downloads
19,102,281
decreased by-9.81%

Weekly downloads

Package description

What is which-module?

The which-module npm package is designed to help developers identify the module object for a given request. This is particularly useful in scenarios where you need to know which module is calling a function or when debugging to understand the module dependency tree. It provides a straightforward API to get the module based on a reference to it.

What are which-module's main functionalities?

Identifying the module for a given reference

This feature allows developers to find out the module object for a specific reference. In the code sample, `which-module` is used to identify the module object for 'some-module' by accessing it through `require.cache` and `require.resolve`. This can be particularly useful for debugging purposes or when implementing custom module loaders or handlers.

const whichModule = require('which-module');
const moduleInfo = whichModule(require.cache[require.resolve('some-module')]);
console.log(moduleInfo);

Other packages similar to which-module

Readme

Source

which-module

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

Build Status Coverage Status Standard Version

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

Keywords

FAQs

Last updated on 01 May 2017

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc