
Product
Introducing Webhook Events for Alert Changes
Add real-time Socket webhook events to your workflows to automatically receive software supply chain alert changes in real time.
which-module
Advanced tools
Find the module object for something that was require()d
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.
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' ] }
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.
ISC © Contributors
The 'resolve' package is similar to 'which-module' in that it helps with module resolution. However, 'resolve' focuses more on asynchronously resolving the path of a module according to the Node.js `require.resolve` algorithm, rather than identifying the module object itself. It's more about finding where a module is located rather than identifying the module's object.
The 'caller' package provides functionality to identify the caller of a function, which can indirectly help in understanding module interactions. While 'which-module' directly identifies the module object for a given reference, 'caller' helps in tracing back the call stack to see which module or function made the current call. This can be useful for debugging or tracking function calls across modules.
FAQs
Find the module object for something that was require()d
The npm package which-module receives a total of 15,635,257 weekly downloads. As such, which-module popularity was classified as popular.
We found that which-module demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
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.

Product
Add real-time Socket webhook events to your workflows to automatically receive software supply chain alert changes in real time.

Security News
ENISA has become a CVE Program Root, giving the EU a central authority for coordinating vulnerability reporting, disclosure, and cross-border response.

Product
Socket now scans OpenVSX extensions, giving teams early detection of risky behaviors, hidden capabilities, and supply chain threats in developer tools.