File: globals.html

package info (click to toggle)
nodejs 4.8.2~dfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 62,476 kB
  • ctags: 111,183
  • sloc: cpp: 661,544; ansic: 31,406; python: 23,073; makefile: 1,418; sh: 1,384; perl: 255; lisp: 222; ruby: 76; xml: 50
file content (308 lines) | stat: -rw-r--r-- 17,596 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>Global Objects | Node.js v4.8.2 Manual &amp; Documentation</title>
  <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Lato:400,700,400italic">
  <link rel="stylesheet" href="assets/style.css">
  <link rel="stylesheet" href="assets/sh.css">
  <link rel="canonical" href="https://nodejs.org/api/globals.html">
</head>
<body class="alt apidoc" id="api-section-globals">
  <div id="content" class="clearfix">
    <div id="column2" class="interior">
      <div id="intro" class="interior">
        <a href="/" title="Go back to the home page">
          Node.js
        </a>
      </div>
      <ul>
<li><a class="nav-documentation" href="documentation.html">About these Docs</a></li>
<li><a class="nav-synopsis" href="synopsis.html">Usage &amp; Example</a></li>
</ul>
<div class="line"></div>

<ul>
<li><a class="nav-assert" href="assert.html">Assertion Testing</a></li>
<li><a class="nav-buffer" href="buffer.html">Buffer</a></li>
<li><a class="nav-addons" href="addons.html">C/C++ Addons</a></li>
<li><a class="nav-child_process" href="child_process.html">Child Processes</a></li>
<li><a class="nav-cluster" href="cluster.html">Cluster</a></li>
<li><a class="nav-cli" href="cli.html">Command Line Options</a></li>
<li><a class="nav-console" href="console.html">Console</a></li>
<li><a class="nav-crypto" href="crypto.html">Crypto</a></li>
<li><a class="nav-debugger" href="debugger.html">Debugger</a></li>
<li><a class="nav-dns" href="dns.html">DNS</a></li>
<li><a class="nav-domain" href="domain.html">Domain</a></li>
<li><a class="nav-errors" href="errors.html">Errors</a></li>
<li><a class="nav-events" href="events.html">Events</a></li>
<li><a class="nav-fs" href="fs.html">File System</a></li>
<li><a class="nav-globals active" href="globals.html">Globals</a></li>
<li><a class="nav-http" href="http.html">HTTP</a></li>
<li><a class="nav-https" href="https.html">HTTPS</a></li>
<li><a class="nav-modules" href="modules.html">Modules</a></li>
<li><a class="nav-net" href="net.html">Net</a></li>
<li><a class="nav-os" href="os.html">OS</a></li>
<li><a class="nav-path" href="path.html">Path</a></li>
<li><a class="nav-process" href="process.html">Process</a></li>
<li><a class="nav-punycode" href="punycode.html">Punycode</a></li>
<li><a class="nav-querystring" href="querystring.html">Query Strings</a></li>
<li><a class="nav-readline" href="readline.html">Readline</a></li>
<li><a class="nav-repl" href="repl.html">REPL</a></li>
<li><a class="nav-stream" href="stream.html">Stream</a></li>
<li><a class="nav-string_decoder" href="string_decoder.html">String Decoder</a></li>
<li><a class="nav-timers" href="timers.html">Timers</a></li>
<li><a class="nav-tls" href="tls.html">TLS/SSL</a></li>
<li><a class="nav-tty" href="tty.html">TTY</a></li>
<li><a class="nav-dgram" href="dgram.html">UDP/Datagram</a></li>
<li><a class="nav-url" href="url.html">URL</a></li>
<li><a class="nav-util" href="util.html">Utilities</a></li>
<li><a class="nav-v8" href="v8.html">V8</a></li>
<li><a class="nav-vm" href="vm.html">VM</a></li>
<li><a class="nav-zlib" href="zlib.html">ZLIB</a></li>
</ul>
<div class="line"></div>

<ul>
<li><a class="nav-https-github-com-nodejs-node" href="https://github.com/nodejs/node">GitHub Repo &amp; Issue Tracker</a></li>
<li><a class="nav-http-groups-google-com-group-nodejs" href="http://groups.google.com/group/nodejs">Mailing List</a></li>
</ul>

    </div>

    <div id="column1" data-id="globals" class="interior">
      <header>
        <h1>Node.js v4.8.2 Documentation</h1>
        <div id="gtoc">
          <p>
            <a href="index.html" name="toc">Index</a> |
            <a href="all.html">View on single page</a> |
            <a href="globals.json">View as JSON</a>
          </p>
        </div>
        <hr>
      </header>

      <div id="toc">
        <h2>Table of Contents</h2>
        <ul>
<li><span class="stability_undefined"><a href="#globals_global_objects">Global Objects</a></span><ul>
<li><span class="stability_undefined"><a href="#globals_class_buffer">Class: Buffer</a></span></li>
<li><span class="stability_undefined"><a href="#globals_dirname">__dirname</a></span></li>
<li><span class="stability_undefined"><a href="#globals_filename">__filename</a></span></li>
<li><span class="stability_undefined"><a href="#globals_clearimmediate_immediateobject">clearImmediate(immediateObject)</a></span></li>
<li><span class="stability_undefined"><a href="#globals_clearinterval_intervalobject">clearInterval(intervalObject)</a></span></li>
<li><span class="stability_undefined"><a href="#globals_cleartimeout_timeoutobject">clearTimeout(timeoutObject)</a></span></li>
<li><span class="stability_undefined"><a href="#globals_console">console</a></span></li>
<li><span class="stability_undefined"><a href="#globals_exports">exports</a></span></li>
<li><span class="stability_undefined"><a href="#globals_global">global</a></span></li>
<li><span class="stability_undefined"><a href="#globals_module">module</a></span></li>
<li><span class="stability_undefined"><a href="#globals_process">process</a></span></li>
<li><span class="stability_undefined"><a href="#globals_require">require()</a></span><ul>
<li><span class="stability_undefined"><a href="#globals_require_cache">require.cache</a></span></li>
<li><span class="stability_0"><a href="#globals_require_extensions">require.extensions</a></span></li>
<li><span class="stability_undefined"><a href="#globals_require_resolve">require.resolve()</a></span></li>
</ul>
</li>
<li><span class="stability_undefined"><a href="#globals_setimmediate_callback_arg">setImmediate(callback[, arg][, ...])</a></span></li>
<li><span class="stability_undefined"><a href="#globals_setinterval_callback_delay_arg">setInterval(callback, delay[, arg][, ...])</a></span></li>
<li><span class="stability_undefined"><a href="#globals_settimeout_callback_delay_arg">setTimeout(callback, delay[, arg][, ...])</a></span></li>
</ul>
</li>
</ul>

      </div>

      <div id="apicontent">
        <h1>Global Objects<span><a class="mark" href="#globals_global_objects" id="globals_global_objects">#</a></span></h1>
<!-- type=misc -->
<p>These objects are available in all modules. Some of these objects aren&#39;t
actually in the global scope but in the module scope - this will be noted.</p>
<p>The objects listed here are specific to Node.js. There are a number of
<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects">built-in objects</a> that are part of the JavaScript language itself, which are
also globally accessible.</p>
<h2>Class: Buffer<span><a class="mark" href="#globals_class_buffer" id="globals_class_buffer">#</a></span></h2>
<div class="api_metadata">
<span>Added in: v0.1.103</span>
</div><!-- type=global -->
<ul>
<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&lt;Function&gt;</a></li>
</ul>
<p>Used to handle binary data. See the <a href="buffer.html">buffer section</a>.</p>
<h2>__dirname<span><a class="mark" href="#globals_dirname" id="globals_dirname">#</a></span></h2>
<div class="api_metadata">
<span>Added in: v0.1.27</span>
</div><!-- type=var -->
<ul>
<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;String&gt;</a></li>
</ul>
<p>The directory name of the current module. This the same as the
<a href="path.html#path_path_dirname_path"><code>path.dirname()</code></a> of the <a href="#globals_filename"><code>__filename</code></a>.</p>
<p><code>__dirname</code> isn&#39;t actually a global but rather local to each module.</p>
<p>Example: running <code>node example.js</code> from <code>/Users/mjr</code></p>
<pre><code class="lang-js">console.log(__dirname);
// Prints: /Users/mjr
console.log(path.dirname(__filename));
// Prints: /Users/mjr
</code></pre>
<h2>__filename<span><a class="mark" href="#globals_filename" id="globals_filename">#</a></span></h2>
<div class="api_metadata">
<span>Added in: v0.0.1</span>
</div><!-- type=var -->
<ul>
<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;String&gt;</a></li>
</ul>
<p>The file name of the current module. This is the resolved absolute path of the
current module file.</p>
<p>For a main program this is not necessarily the same as the file name used in the
command line.</p>
<p>See <a href="#globals_dirname"><code>__dirname</code></a> for the directory name of the current module.</p>
<p><code>__filename</code> isn&#39;t actually a global but rather local to each module.</p>
<p>Examples:</p>
<p>Running <code>node example.js</code> from <code>/Users/mjr</code></p>
<pre><code class="lang-js">console.log(__filename);
// Prints: /Users/mjr/example.js
console.log(__dirname);
// Prints: /Users/mjr
</code></pre>
<p>Given two modules: <code>a</code> and <code>b</code>, where <code>b</code> is a dependency of
<code>a</code> and there is a directory structure of:</p>
<ul>
<li><code>/Users/mjr/app/a.js</code></li>
<li><code>/Users/mjr/app/node_modules/b/b.js</code></li>
</ul>
<p>References to <code>__filename</code> within <code>b.js</code> will return
<code>/Users/mjr/app/node_modules/b/b.js</code> while references to <code>__filename</code> within
<code>a.js</code> will return <code>/Users/mjr/app/a.js</code>.</p>
<h2>clearImmediate(immediateObject)<span><a class="mark" href="#globals_clearimmediate_immediateobject" id="globals_clearimmediate_immediateobject">#</a></span></h2>
<div class="api_metadata">
<span>Added in: v0.9.1</span>
</div><!--type=global-->
<p><a href="timers.html#timers_clearimmediate_immediateobject"><code>clearImmediate</code></a> is described in the <a href="timers.html">timers</a> section.</p>
<h2>clearInterval(intervalObject)<span><a class="mark" href="#globals_clearinterval_intervalobject" id="globals_clearinterval_intervalobject">#</a></span></h2>
<div class="api_metadata">
<span>Added in: v0.0.1</span>
</div><!--type=global-->
<p><a href="timers.html#timers_clearinterval_intervalobject"><code>clearInterval</code></a> is described in the <a href="timers.html">timers</a> section.</p>
<h2>clearTimeout(timeoutObject)<span><a class="mark" href="#globals_cleartimeout_timeoutobject" id="globals_cleartimeout_timeoutobject">#</a></span></h2>
<div class="api_metadata">
<span>Added in: v0.0.1</span>
</div><!--type=global-->
<p><a href="timers.html#timers_cleartimeout_timeoutobject"><code>clearTimeout</code></a> is described in the <a href="timers.html">timers</a> section.</p>
<h2>console<span><a class="mark" href="#globals_console" id="globals_console">#</a></span></h2>
<div class="api_metadata">
<span>Added in: v0.1.100</span>
</div><!-- type=global -->
<ul>
<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&lt;Object&gt;</a></li>
</ul>
<p>Used to print to stdout and stderr. See the <a href="console.html"><code>console</code></a> section.</p>
<h2>exports<span><a class="mark" href="#globals_exports" id="globals_exports">#</a></span></h2>
<div class="api_metadata">
<span>Added in: v0.1.12</span>
</div><!-- type=var -->
<p>A reference to the <code>module.exports</code> that is shorter to type.
See <a href="modules.html">module system documentation</a> for details on when to use <code>exports</code> and
when to use <code>module.exports</code>.</p>
<p><code>exports</code> isn&#39;t actually a global but rather local to each module.</p>
<p>See the <a href="modules.html">module system documentation</a> for more information.</p>
<h2>global<span><a class="mark" href="#globals_global" id="globals_global">#</a></span></h2>
<div class="api_metadata">
<span>Added in: v0.1.27</span>
</div><!-- type=global -->
<ul>
<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&lt;Object&gt;</a> The global namespace object.</li>
</ul>
<p>In browsers, the top-level scope is the global scope. That means that in
browsers if you&#39;re in the global scope <code>var something</code> will define a global
variable. In Node.js this is different. The top-level scope is not the global
scope; <code>var something</code> inside an Node.js module will be local to that module.</p>
<h2>module<span><a class="mark" href="#globals_module" id="globals_module">#</a></span></h2>
<div class="api_metadata">
<span>Added in: v0.1.16</span>
</div><!-- type=var -->
<ul>
<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&lt;Object&gt;</a></li>
</ul>
<p>A reference to the current module. In particular
<code>module.exports</code> is used for defining what a module exports and makes
available through <code>require()</code>.</p>
<p><code>module</code> isn&#39;t actually a global but rather local to each module.</p>
<p>See the <a href="modules.html">module system documentation</a> for more information.</p>
<h2>process<span><a class="mark" href="#globals_process" id="globals_process">#</a></span></h2>
<div class="api_metadata">
<span>Added in: v0.1.7</span>
</div><!-- type=global -->
<ul>
<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&lt;Object&gt;</a></li>
</ul>
<p>The process object. See the <a href="process.html#process_process"><code>process</code> object</a> section.</p>
<h2>require()<span><a class="mark" href="#globals_require" id="globals_require">#</a></span></h2>
<div class="api_metadata">
<span>Added in: v0.1.13</span>
</div><!-- type=var -->
<ul>
<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&lt;Function&gt;</a></li>
</ul>
<p>To require modules. See the <a href="modules.html#modules_modules">Modules</a> section.  <code>require</code> isn&#39;t actually a
global but rather local to each module.</p>
<h3>require.cache<span><a class="mark" href="#globals_require_cache" id="globals_require_cache">#</a></span></h3>
<div class="api_metadata">
<span>Added in: v0.3.0</span>
</div><ul>
<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&lt;Object&gt;</a></li>
</ul>
<p>Modules are cached in this object when they are required. By deleting a key
value from this object, the next <code>require</code> will reload the module. Note that
this does not apply to <a href="addons.html">native addons</a>, for which reloading will result in an
Error.</p>
<h3>require.extensions<span><a class="mark" href="#globals_require_extensions" id="globals_require_extensions">#</a></span></h3>
<div class="api_metadata">
<span>Added in: v0.3.0</span>
<span>Deprecated since: v0.10.6 </span>
</div><pre class="api_stability api_stability_0">Stability: 0 - Deprecated</pre><ul>
<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&lt;Object&gt;</a></li>
</ul>
<p>Instruct <code>require</code> on how to handle certain file extensions.</p>
<p>Process files with the extension <code>.sjs</code> as <code>.js</code>:</p>
<pre><code class="lang-js">require.extensions[&#39;.sjs&#39;] = require.extensions[&#39;.js&#39;];
</code></pre>
<p><strong>Deprecated</strong>  In the past, this list has been used to load
non-JavaScript modules into Node.js by compiling them on-demand.
However, in practice, there are much better ways to do this, such as
loading modules via some other Node.js program, or compiling them to
JavaScript ahead of time.</p>
<p>Since the Module system is locked, this feature will probably never go
away.  However, it may have subtle bugs and complexities that are best
left untouched.</p>
<h3>require.resolve()<span><a class="mark" href="#globals_require_resolve" id="globals_require_resolve">#</a></span></h3>
<div class="api_metadata">
<span>Added in: v0.3.0</span>
</div><p>Use the internal <code>require()</code> machinery to look up the location of a module,
but rather than loading the module, just return the resolved filename.</p>
<h2>setImmediate(callback[, arg][, ...])<span><a class="mark" href="#globals_setimmediate_callback_arg" id="globals_setimmediate_callback_arg">#</a></span></h2>
<div class="api_metadata">
<span>Added in: v0.9.1</span>
</div><!-- type=global -->
<p><a href="timers.html#timers_setimmediate_callback_arg"><code>setImmediate</code></a> is described in the <a href="timers.html">timers</a> section.</p>
<h2>setInterval(callback, delay[, arg][, ...])<span><a class="mark" href="#globals_setinterval_callback_delay_arg" id="globals_setinterval_callback_delay_arg">#</a></span></h2>
<div class="api_metadata">
<span>Added in: v0.0.1</span>
</div><!-- type=global -->
<p><a href="timers.html#timers_setinterval_callback_delay_arg"><code>setInterval</code></a> is described in the <a href="timers.html">timers</a> section.</p>
<h2>setTimeout(callback, delay[, arg][, ...])<span><a class="mark" href="#globals_settimeout_callback_delay_arg" id="globals_settimeout_callback_delay_arg">#</a></span></h2>
<div class="api_metadata">
<span>Added in: v0.0.1</span>
</div><!-- type=global -->
<p><a href="timers.html#timers_settimeout_callback_delay_arg"><code>setTimeout</code></a> is described in the <a href="timers.html">timers</a> section.</p>

      </div>
    </div>
  </div>
  <script src="assets/sh_main.js"></script>
  <script src="assets/sh_javascript.min.js"></script>
  <script>highlight(undefined, undefined, 'pre');</script>
  <!-- __TRACKING__ -->
</body>
</html>