- Assertion testing
- Async hooks
- Buffer
- C++ addons
- C/C++ addons with Node-API
- C++ embedder API
- Child processes
- Cluster
- Command-line options
- Console
- Crypto
- Debugger
- Deprecated APIs
- Diagnostics Channel
- DNS
- Domain
- Errors
- Events
- File system
- Globals
- HTTP
- HTTP/2
- HTTPS
- Inspector
- Internationalization
- Modules: CommonJS modules
- Modules: ECMAScript modules
- Modules:
moduleAPI - Modules: Packages
- Net
- OS
- Path
- Performance hooks
- Policies
- Process
- Punycode
- Query strings
- Readline
- REPL
- Report
- Stream
- String decoder
- Timers
- TLS/SSL
- Trace events
- TTY
- UDP/datagram
- URL
- Utilities
- V8
- VM
- WASI
- Worker threads
- Zlib
Node.js v14.17.4 documentation
Table of contents
- Global objects
- Class:
AbortController - Class:
Buffer __dirname__filenameclearImmediate(immediateObject)clearInterval(intervalObject)clearTimeout(timeoutObject)consoleexportsglobalmoduleprocessqueueMicrotask(callback)require()setImmediate(callback[, ...args])setInterval(callback, delay[, ...args])setTimeout(callback, delay[, ...args])TextDecoderTextEncoderURLURLSearchParamsWebAssembly
- Class:
Global objects#
These objects are available in all modules. The following variables may appear to be global but are not. They exist only in the scope of modules, see the module system documentation:
The objects listed here are specific to Node.js. There are built-in objects that are part of the JavaScript language itself, which are also globally accessible.
Class: AbortController#
A utility class used to signal cancelation in selected Promise-based APIs.
The API is based on the Web API AbortController.
To use, launch Node.js using the --experimental-abortcontroller flag.
const ac = new AbortController();
ac.signal.addEventListener('abort', () => console.log('Aborted!'),
{ once: true });
ac.abort();
console.log(ac.signal.aborted); // Prints True
abortController.abort()#
Triggers the abort signal, causing the abortController.signal to emit
the 'abort' event.
abortController.signal#
- Type: <AbortSignal>
Class: AbortSignal#
- Extends: <EventTarget>
The AbortSignal is used to notify observers when the
abortController.abort() method is called.
Static method: AbortSignal.abort()#
- Returns: <AbortSignal>
Returns a new already aborted AbortSignal.
Event: 'abort'#
The 'abort' event is emitted when the abortController.abort() method
is called. The callback is invoked with a single object argument with a
single type property set to 'abort':
const ac = new AbortController();
// Use either the onabort property...
ac.signal.onabort = () => console.log('aborted!');
// Or the EventTarget API...
ac.signal.addEventListener('abort', (event) => {
console.log(event.type); // Prints 'abort'
}, { once: true });
ac.abort();
The AbortController with which the AbortSignal is associated will only
ever trigger the 'abort' event once. We recommended that code check
that the abortSignal.aborted attribute is false before adding an 'abort'
event listener.
Any event listeners attached to the AbortSignal should use the
{ once: true } option (or, if using the EventEmitter APIs to attach a
listener, use the once() method) to ensure that the event listener is
removed as soon as the 'abort' event is handled. Failure to do so may
result in memory leaks.
abortSignal.aborted#
- Type: <boolean> True after the
AbortControllerhas been aborted.
abortSignal.onabort#
- Type: <Function>
An optional callback function that may be set by user code to be notified
when the abortController.abort() function has been called.
Class: Buffer#
Used to handle binary data. See the buffer section.
__dirname#
This variable may appear to be global but is not. See __dirname.
__filename#
This variable may appear to be global but is not. See __filename.
clearImmediate(immediateObject)#
clearImmediate is described in the timers section.
clearInterval(intervalObject)#
clearInterval is described in the timers section.
clearTimeout(timeoutObject)#
clearTimeout is described in the timers section.