## Global Objects
-These object are available in the global scope and can be accessed from anywhere.
+These object are available in all modules. Some of these objects aren't
+actually in the global scope but in the module scope - this will be noted.
### global
### require()
To require modules. See the [Modules](modules.html#modules) section.
+`require` isn't actually a global but rather local to each module.
+
### require.resolve()
console.log(__filename);
// /Users/mjr/example.js
+`__filename` isn't actually a global but rather local to each module.
+
### __dirname
The dirname of the script being executed.
console.log(__dirname);
// /Users/mjr
+`__dirname` isn't actually a global but rather local to each module.
+
### module
### clearInterval(t)
The timer functions are global variables. See the [timers](timers.html) section.
+
+`module` isn't actually a global but rather local to each module.
(among other things) that every call to `require('foo')` will get
exactly the same object returned, if it would resolve to the same file.
+### module.exports
+
+The `exports` object is created by the Module system. Sometimes this is not
+acceptable, many want their module to be an instance of some class. To do this
+assign the desired export object to `module.exports`. For example suppose we
+were making a module called `a.js`
+
+ var EventEmitter = require('events').EventEmitter;
+
+ module.exports = new EventEmitter();
+
+ // Do some work, and after some time emit
+ // the 'ready' event from the module itself.
+ setTimeout(function() {
+ module.exports.emit('ready');
+ }, 1000);
+
+Then in another file we could do
+
+ var a = require('./a');
+ a.on('ready', function() {
+ console.log('module a is ready');
+ });
+
+
+Note that assignment to `module.exports` must be done immediately. It cannot be
+done in any callbacks. This does not work:
+
+x.js:
+
+ setTimeout(function() {
+ module.exports = { a: "hello" };
+ }, 0);
+
+y.js
+
+ var x = require('./x');
+ console.log(x.a);
+
+
+
+
+
+
+
### All Together...
To get the exact filename that will be loaded when `require()` is called, use