I am working on a CMS system for Node.js, I have a quick question for those Node.js Pro’s
I am creating modules and requiring modules within those modules, but if I have already included this module in the parent module, can I access those required modules?
For Example:
main.js
var fs = require('fs');
var sc = require('second.js');
second.js
var fs = require('fs'); // Is there any way to use the parent modules fs object?
It just seems I am including the same modules in some of my sub modules and rather not do that if possible.
Thanks!
It shouldn’t matter, since Node caches modules when they’re first included (i.e. the side-effects of requiring a module won’t be executed a second time). You can force this cache to be cleared (and thus re-execute said side-effects) by tampering with
require.cache.