Search code examples
node.jsrequire

Find out what file is requiring another file in Node


The title says pretty much what I need to do.

I have a module in node_modules which prints something to the standard output (and I don't want this to happen) but I don't find where I'm requiring this file.

I may be misunderstanding how modules are included, as I though that they must be required in order to be executed.


Solution

  • There are multiple ways for stuff to write to output. If it's just using console.log(), just swap in trace. Before your require() statements:

    console.log = console.trace;
    

    Then, you'll have the full trace output every time there's a log.