doc: consolidate timers docs in timers.markdown
[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 ## Class: Buffer
9
10 <!-- type=global -->
11
12 * {Function}
13
14 Used to handle binary data. See the [buffer section][].
15
16 ## \_\_dirname
17
18 <!-- type=var -->
19
20 * {String}
21
22 The name of the directory that the currently executing script resides in.
23
24 Example: running `node example.js` from `/Users/mjr`
25
26 ```js
27 console.log(__dirname);
28 // /Users/mjr
29 ```
30
31 `__dirname` isn't actually a global but rather local to each module.
32
33 ## \_\_filename
34
35 <!-- type=var -->
36
37 * {String}
38
39 The filename of the code being executed.  This is the resolved absolute path
40 of this code file.  For a main program this is not necessarily the same
41 filename used in the command line.  The value inside a module is the path
42 to that module file.
43
44 Example: running `node example.js` from `/Users/mjr`
45
46 ```js
47 console.log(__filename);
48 // /Users/mjr/example.js
49 ```
50
51 `__filename` isn't actually a global but rather local to each module.
52
53 ## clearImmediate(immediateObject)
54
55 <!--type=global-->
56
57 [`clearImmediate`] is described in the [timers][] section.
58
59 ## clearInterval(intervalObject)
60
61 <!--type=global-->
62
63 [`clearInterval`] is described in the [timers][] section.
64
65 ## clearTimeout(timeoutObject)
66
67 <!--type=global-->
68
69 [`clearTimeout`] is described in the [timers][] section.
70
71 ## console
72
73 <!-- type=global -->
74
75 * {Object}
76
77 Used to print to stdout and stderr. See the [`console`][] section.
78
79 ## exports
80
81 <!-- type=var -->
82
83 A reference to the `module.exports` that is shorter to type.
84 See [module system documentation][] for details on when to use `exports` and
85 when to use `module.exports`.
86
87 `exports` isn't actually a global but rather local to each module.
88
89 See the [module system documentation][] for more information.
90
91 ## global
92
93 <!-- type=global -->
94
95 * {Object} The global namespace object.
96
97 In browsers, the top-level scope is the global scope. That means that in
98 browsers if you're in the global scope `var something` will define a global
99 variable. In Node.js this is different. The top-level scope is not the global
100 scope; `var something` inside an Node.js module will be local to that module.
101
102 ## module
103
104 <!-- type=var -->
105
106 * {Object}
107
108 A reference to the current module. In particular
109 `module.exports` is used for defining what a module exports and makes
110 available through `require()`.
111
112 `module` isn't actually a global but rather local to each module.
113
114 See the [module system documentation][] for more information.
115
116 ## process
117
118 <!-- type=global -->
119
120 * {Object}
121
122 The process object. See the [`process` object][] section.
123
124 ## require()
125
126 <!-- type=var -->
127
128 * {Function}
129
130 To require modules. See the [Modules][] section.  `require` isn't actually a
131 global but rather local to each module.
132
133 ### require.cache
134
135 * {Object}
136
137 Modules are cached in this object when they are required. By deleting a key
138 value from this object, the next `require` will reload the module.
139
140 ### require.extensions
141
142     Stability: 0 - Deprecated
143
144 * {Object}
145
146 Instruct `require` on how to handle certain file extensions.
147
148 Process files with the extension `.sjs` as `.js`:
149
150 ```js
151 require.extensions['.sjs'] = require.extensions['.js'];
152 ```
153
154 **Deprecated**  In the past, this list has been used to load
155 non-JavaScript modules into Node.js by compiling them on-demand.
156 However, in practice, there are much better ways to do this, such as
157 loading modules via some other Node.js program, or compiling them to
158 JavaScript ahead of time.
159
160 Since the Module system is locked, this feature will probably never go
161 away.  However, it may have subtle bugs and complexities that are best
162 left untouched.
163
164 ### require.resolve()
165
166 Use the internal `require()` machinery to look up the location of a module,
167 but rather than loading the module, just return the resolved filename.
168
169 ## setImmediate(callback[, arg][, ...])
170
171 <!-- type=global -->
172
173 [`setImmediate`] is described in the [timers][] section.
174
175 ## setInterval(callback, delay[, arg][, ...])
176
177 <!-- type=global -->
178
179 [`setInterval`] is described in the [timers][] section.
180
181 ## setTimeout(callback, delay[, arg][, ...])
182
183 <!-- type=global -->
184
185 [`setTimeout`] is described in the [timers][] section.
186
187 [`console`]: console.html
188 [`process` object]: process.html#process_process
189 [buffer section]: buffer.html
190 [module system documentation]: modules.html
191 [Modules]: modules.html#modules_modules
192 [timers]: timers.html
193 [`clearImmediate`]: timers.html#timers_clearimmediate_immediateobject
194 [`clearInterval`]: timers.html#timers_clearinterval_intervalobject
195 [`clearTimeout`]: timers.html#timers_cleartimeout_timeoutobject
196 [`setImmediate`]: timers.html#timers_setimmediate_callback_arg
197 [`setInterval`]: timers.html#timers_setinterval_callback_delay_arg
198 [`setTimeout`]: timers.html#timers_settimeout_callback_delay_arg