Is it possible to access * loaded * children of a nodejs module?
Let's say I have 3 modules with dependencies like this:
A.js
var b = require('./B');
var c = require('./C');
console.log(module.children.length); // 2
      
        
        
        
      
    B.js
var z = require('Z');
console.log(module.children.length); // 1
      
        
        
        
      
    C.js
var z = require('Z');
console.log(module.children.length); // 0 ?!?!
      
        
        
        
      
     Z
      
        
        
        
      
    does not appear in the module.children
      
        
        
        
      
    inside C
      
        
        
        
      
    because it was already loaded B
      
        
        
        
      
    before execution C
      
        
        
        
      
    .
I can figure out module.parent
      
        
        
        
      
    of Z
      
        
        
        
      
    how B
      
        
        
        
      
    because the first place was loaded, but Z
      
        
        
        
      
    can certainly be a child of B
      
        
        
        
      
    and C
      
        
        
        
      
    ?
Anyway, my question is, is it possible to see all the children of a module, regardless of whether they have been loaded or not?
I had a similar problem in the past and manually deleted the cache, in your case for the C module.
C.js
delete require.cache[require.resolve('./Z')];
var z = require('./Z'); // 1
      
        
        
        
      
    I'm not sure if this is an acceptable solution for you.