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