doc: update node.js references in api docs
[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 io.js this is different. The top-level scope is not the global
17 scope; `var something` inside an io.js 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][] section.
26
27 ## console
28
29 <!-- type=global -->
30
31 * {Object}
32
33 Used to print to stdout and stderr. See the [console][] section.
34
35 ## Class: Buffer
36
37 <!-- type=global -->
38
39 * {Function}
40
41 Used to handle binary data. See the [buffer section][]
42
43 ## require()
44
45 <!-- type=var -->
46
47 * {Function}
48
49 To require modules. See the [Modules][] section.  `require` isn't actually a
50 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 ### require.extensions
65
66     Stability: 0 - Deprecated
67
68 * {Object}
69
70 Instruct `require` on how to handle certain file extensions.
71
72 Process files with the extension `.sjs` as `.js`:
73
74     require.extensions['.sjs'] = require.extensions['.js'];
75
76 **Deprecated**  In the past, this list has been used to load
77 non-JavaScript modules into io.js by compiling them on-demand.
78 However, in practice, there are much better ways to do this, such as
79 loading modules via some other io.js program, or compiling them to
80 JavaScript ahead of time.
81
82 Since the Module system is locked, this feature will probably never go
83 away.  However, it may have subtle bugs and complexities that are best
84 left untouched.
85
86 ## __filename
87
88 <!-- type=var -->
89
90 * {String}
91
92 The filename of the code being executed.  This is the resolved absolute path
93 of this code file.  For a main program this is not necessarily the same
94 filename used in the command line.  The value inside a module is the path
95 to that module file.
96
97 Example: running `iojs example.js` from `/Users/mjr`
98
99     console.log(__filename);
100     // /Users/mjr/example.js
101
102 `__filename` isn't actually a global but rather local to each module.
103
104 ## __dirname
105
106 <!-- type=var -->
107
108 * {String}
109
110 The name of the directory that the currently executing script resides in.
111
112 Example: running `iojs example.js` from `/Users/mjr`
113
114     console.log(__dirname);
115     // /Users/mjr
116
117 `__dirname` isn't actually a global but rather local to each module.
118
119
120 ## module
121
122 <!-- type=var -->
123
124 * {Object}
125
126 A reference to the current module. In particular
127 `module.exports` is used for defining what a module exports and makes
128 available through `require()`.
129
130 `module` isn't actually a global but rather local to each module.
131
132 See the [module system documentation][] for more information.
133
134 ## exports
135
136 <!-- type=var -->
137
138 A reference to the `module.exports` that is shorter to type.
139 See [module system documentation][] for details on when to use `exports` and
140 when to use `module.exports`.
141
142 `exports` isn't actually a global but rather local to each module.
143
144 See the [module system documentation][] for more information.
145
146 See the [module section][] for more information.
147
148 ## setTimeout(cb, ms)
149
150 Run callback `cb` after *at least* `ms` milliseconds. The actual delay depends
151 on external factors like OS timer granularity and system load.
152
153 The timeout must be in the range of 1-2,147,483,647 inclusive. If the value is
154 outside that range, it's changed to 1 millisecond. Broadly speaking, a timer
155 cannot span more than 24.8 days.
156
157 Returns an opaque value that represents the timer.
158
159 ## clearTimeout(t)
160
161 Stop a timer that was previously created with `setTimeout()`. The callback will
162 not execute.
163
164 ## setInterval(cb, ms)
165
166 Run callback `cb` repeatedly every `ms` milliseconds. Note that the actual
167 interval may vary, depending on external factors like OS timer granularity and
168 system load. It's never less than `ms` but it may be longer.
169
170 The interval must be in the range of 1-2,147,483,647 inclusive. If the value is
171 outside that range, it's changed to 1 millisecond. Broadly speaking, a timer
172 cannot span more than 24.8 days.
173
174 Returns an opaque value that represents the timer.
175
176 ## clearInterval(t)
177
178 Stop a timer that was previously created with `setInterval()`. The callback
179 will not execute.
180
181 <!--type=global-->
182
183 The timer functions are global variables. See the [timers][] section.
184
185 [buffer section]: buffer.html
186 [module section]: modules.html
187 [module system documentation]: modules.html
188 [Modules]: modules.html#modules_modules
189 [process object]: process.html#process_process
190 [console]: console.html
191 [timers]: timers.html