List of currently loaded node.js modules?

Posted on

List of currently loaded node.js modules?

Is there a function in node.js that gives me all currently loaded modules – or even better, their filenames?

I want to restart my process as soon as a loaded module gets updated and so need to know which files need to be monitored for changes…

Solution :

Check the module module source. Your answer is:


To complement Anatoliy’s helpful answer:

Since Node.js v0.3.0, require.cache contains the loaded non-core modules:

 Object.keys(require.cache);  # lists full filenames of loaded non-core modules

The advantage of require.cache is that it is documented, unlike module._cache.


  • Core modules such as util do NOT show up in require.cache.

    • To test if a module is a core module, use require.resolve(<name>): if it returns <name>, i.e., merely the module name itself, the module is core; non-core modules will return their full filename.
  • require.cache contains a hash of all currently loaded non-core modules as module instances, keyed by their full filenames.

Leave a Reply

Your email address will not be published. Required fields are marked *