Lets say I’ve run the following code:
var toType = function(obj){
return ({}).toString.call(obj).match(/\s([a-zA-Z]+)/)[1].toLowerCase();
};
var someModule = require("./path/to/name");
console.log(toType(require.cache["./path/to/name"]));
someModule();
in the location ./path/to/name.js I have the following code:
module.exports = function (){
console.log("Hell World!");
};
These two snippets don’t run, so I figured I’m missing something here. The output is as following:
node: no process found
undefined
Hell World!
[Finished in 0.1s]
- how does
require("./path/to/name");gets mapped torequire.cache;? - how can I retrieve a module, delete it and check it’s type?
Answers with code will be appreciated.
Running the following works for non-system exports, at least on node 0.8.2:
Note that require.cache is correct; require.cache() is not (it is a property; 0.8.2 won’t compile it.) For this I see:
I’m not sure why a module like ‘http’ doesn’t show up…