Server IP : 127.0.0.2 / Your IP : 13.58.229.23 Web Server : Apache/2.4.18 (Ubuntu) System : User : www-data ( ) PHP Version : 7.0.33-0ubuntu0.16.04.16 Disable Function : disk_free_space,disk_total_space,diskfreespace,dl,exec,fpaththru,getmyuid,getmypid,highlight_file,ignore_user_abord,leak,listen,link,opcache_get_configuration,opcache_get_status,passthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,php_uname,phpinfo,posix_ctermid,posix_getcwd,posix_getegid,posix_geteuid,posix_getgid,posix_getgrgid,posix_getgrnam,posix_getgroups,posix_getlogin,posix_getpgid,posix_getpgrp,posix_getpid,posix,_getppid,posix_getpwnam,posix_getpwuid,posix_getrlimit,posix_getsid,posix_getuid,posix_isatty,posix_kill,posix_mkfifo,posix_setegid,posix_seteuid,posix_setgid,posix_setpgid,posix_setsid,posix_setuid,posix_times,posix_ttyname,posix_uname,pclose,popen,proc_open,proc_close,proc_get_status,proc_nice,proc_terminate,shell_exec,source,show_source,system,virtual MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /usr/share/doc/nodejs/api/ |
Upload File : |
<!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <title>Global Objects Node.js v4.2.6 Manual & Documentation</title> <link rel="stylesheet" href="assets/style.css"> <link rel="stylesheet" href="assets/sh.css"> <link rel="canonical" href="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 (1) </a> </div> <ul> <li><a class="nav-documentation" href="documentation.html">About these Docs</a></li> <li><a class="nav-synopsis" href="synopsis.html">Synopsis</a></li> <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-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> <div id="column1" data-id="globals" class="interior"> <header> <h1>Node.js v4.2.6 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><a href="#globals_global_objects">Global Objects</a><ul> <li><a href="#globals_class_buffer">Class: Buffer</a></li> <li><a href="#globals_dirname">__dirname</a></li> <li><a href="#globals_filename">__filename</a></li> <li><a href="#globals_clearinterval_t">clearInterval(t)</a></li> <li><a href="#globals_cleartimeout_t">clearTimeout(t)</a></li> <li><a href="#globals_console">console</a></li> <li><a href="#globals_exports">exports</a></li> <li><a href="#globals_global">global</a></li> <li><a href="#globals_module">module</a></li> <li><a href="#globals_process">process</a></li> <li><a href="#globals_require">require()</a><ul> <li><a href="#globals_require_cache">require.cache</a></li> <li><a href="#globals_require_extensions">require.extensions</a></li> <li><a href="#globals_require_resolve">require.resolve()</a></li> </ul> </li> <li><a href="#globals_setinterval_cb_ms">setInterval(cb, ms)</a></li> <li><a href="#globals_settimeout_cb_ms">setTimeout(cb, ms)</a></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't actually in the global scope but in the module scope - this will be noted. </p> <h2>Class: Buffer<span><a class="mark" href="#globals_class_buffer" id="globals_class_buffer">#</a></span></h2> <!-- type=global --> <ul> <li>{Function}</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> <!-- type=var --> <ul> <li>{String}</li> </ul> <p>The name of the directory that the currently executing script resides in. </p> <p>Example: running <code>node example.js</code> from <code>/Users/mjr</code> </p> <pre><code>console.log(__dirname); // /Users/mjr</code></pre> <p><code>__dirname</code> isn't actually a global but rather local to each module. </p> <h2>__filename<span><a class="mark" href="#globals_filename" id="globals_filename">#</a></span></h2> <!-- type=var --> <ul> <li>{String}</li> </ul> <p>The filename of the code being executed. This is the resolved absolute path of this code file. For a main program this is not necessarily the same filename used in the command line. The value inside a module is the path to that module file. </p> <p>Example: running <code>node example.js</code> from <code>/Users/mjr</code> </p> <pre><code>console.log(__filename); // /Users/mjr/example.js</code></pre> <p><code>__filename</code> isn't actually a global but rather local to each module. </p> <h2>clearInterval(t)<span><a class="mark" href="#globals_clearinterval_t" id="globals_clearinterval_t">#</a></span></h2> <p>Stop a timer that was previously created with <a href="#globals_setinterval_cb_ms"><code>setInterval()</code></a>. The callback will not execute. </p> <!--type=global--> <p>The timer functions are global variables. See the <a href="timers.html">timers</a> section. </p> <h2>clearTimeout(t)<span><a class="mark" href="#globals_cleartimeout_t" id="globals_cleartimeout_t">#</a></span></h2> <p>Stop a timer that was previously created with <a href="#globals_settimeout_cb_ms"><code>setTimeout()</code></a>. The callback will not execute. </p> <h2>console<span><a class="mark" href="#globals_console" id="globals_console">#</a></span></h2> <!-- type=global --> <ul> <li>{Object}</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> <!-- 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'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> <!-- type=global --> <ul> <li>{Object} The global namespace object.</li> </ul> <p>In browsers, the top-level scope is the global scope. That means that in browsers if you'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> <!-- type=var --> <ul> <li>{Object}</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'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> <!-- type=global --> <ul> <li>{Object}</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> <!-- type=var --> <ul> <li>{Function}</li> </ul> <p>To require modules. See the <a href="modules.html#modules_modules">Modules</a> section. <code>require</code> isn'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="signature"><ul> <li><span class="type">Object</span></li> </div></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. </p> <h3>require.extensions<span><a class="mark" href="#globals_require_extensions" id="globals_require_extensions">#</a></span></h3> <pre class="api_stability_0">Stability: 0 - Deprecated</pre><div class="signature"><ul> <li><span class="type">Object</span></li> </div></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>require.extensions['.sjs'] = require.extensions['.js'];</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> <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>setInterval(cb, ms)<span><a class="mark" href="#globals_setinterval_cb_ms" id="globals_setinterval_cb_ms">#</a></span></h2> <p>Run callback <code>cb</code> repeatedly every <code>ms</code> milliseconds. Note that the actual interval may vary, depending on external factors like OS timer granularity and system load. It's never less than <code>ms</code> but it may be longer. </p> <p>The interval must be in the range of 1-2,147,483,647 inclusive. If the value is outside that range, it's changed to 1 millisecond. Broadly speaking, a timer cannot span more than 24.8 days. </p> <p>Returns an opaque value that represents the timer. </p> <h2>setTimeout(cb, ms)<span><a class="mark" href="#globals_settimeout_cb_ms" id="globals_settimeout_cb_ms">#</a></span></h2> <p>Run callback <code>cb</code> after <em>at least</em> <code>ms</code> milliseconds. The actual delay depends on external factors like OS timer granularity and system load. </p> <p>The timeout must be in the range of 1-2,147,483,647 inclusive. If the value is outside that range, it's changed to 1 millisecond. Broadly speaking, a timer cannot span more than 24.8 days. </p> <p>Returns an opaque value that represents the timer. </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> </body> </html>