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