node.js how to access an already required object

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 to require.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:

var http = require ('http');
var util = require ('util');
var b = require('./b');

util.inspect(require.cache);

var loaded = require.cache;

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:

{ '/home/user/node/a.js':
   { id: '.',
     exports: {},
     parent: null,
     filename: '/home/user/node/a.js',
     loaded: false,
     children: [ [Object] ],
     paths:
      [ '/home/user/node/node_modules',
        '/home/user/node_modules',
        '/home/node_modules',
        '/node_modules' ] },
  '/home/user/node/b.js':
   { id: '/home/user/node/b.js',
     exports: [Function],
     parent:
      { id: '.',
        exports: {},
        parent: null,
        filename: '/home/user/node/a.js',
        loaded: false,
        children: [Object],
        paths: [Object] },
     filename: '/home/user/node/b.js',
     loaded: true,
     children: [],
     paths:
      [ '/home/user/node/node_modules',
        '/home/user/node_modules',
        '/home/node_modules',
        '/node_modules' ] } }

I'm not sure why a module like 'http' doesn't show up...