Merge remote branch 'origin/v0.4'
[platform/upstream/nodejs.git] / doc / api / globals.markdown
1 ## Global Objects
2
3 These objects are available in all modules. Some of these objects aren't
4 actually in the global scope but in the module scope - this will be noted.
5
6 ### global
7
8 The global namespace object.
9
10 In browsers, the top-level scope is the global scope. That means that in
11 browsers if you're in the global scope `var something` will define a global
12 variable. In Node this is different. The top-level scope is not the global
13 scope; `var something` inside a Node module will be local to that module.
14
15 ### process
16
17 The process object. See the [process object](process.html#process) section.
18
19 ### console
20
21 Used to print to stdout and stderr. See the [stdio](stdio.html) section.
22
23 ### Buffer
24
25 Used to handle binary data. See the [buffers](buffers.html) section.
26
27 ### require()
28
29 To require modules. See the [Modules](modules.html#modules) section.
30 `require` isn't actually a global but rather local to each module.
31
32
33 ### require.resolve()
34
35 Use the internal `require()` machinery to look up the location of a module,
36 but rather than loading the module, just return the resolved filename.
37
38 ### require.cache
39
40 Modules are cached in this object when they are required. By deleting a key
41 value from this object, the next `require` will reload the module.
42
43
44 ### __filename
45
46 The filename of the code being executed.  This is the resolved absolute path
47 of this code file.  For a main program this is not necessarily the same
48 filename used in the command line.  The value inside a module is the path
49 to that module file.
50
51 Example: running `node example.js` from `/Users/mjr`
52
53     console.log(__filename);
54     // /Users/mjr/example.js
55
56 `__filename` isn't actually a global but rather local to each module.
57
58 ### __dirname
59
60 The name of the directory that the currently executing script resides in.
61
62 Example: running `node example.js` from `/Users/mjr`
63
64     console.log(__dirname);
65     // /Users/mjr
66
67 `__dirname` isn't actually a global but rather local to each module.
68
69
70 ### module
71
72 A reference to the current module. In particular
73 `module.exports` is the same as the `exports` object. See `src/node.js`
74 for more information.
75 `module` isn't actually a global but rather local to each module.
76
77
78 ### exports
79
80 An object which is shared between all instances of the current module and
81 made accessible through `require()`.
82 `exports` is the same as the `module.exports` object. See `src/node.js`
83 for more information.
84 `exports` isn't actually a global but rather local to each module.
85
86 ### setTimeout(cb, ms)
87 ### clearTimeout(t)
88 ### setInterval(cb, ms)
89 ### clearInterval(t)
90
91 The timer functions are global variables. See the [timers](timers.html) section.