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