Notable Changes: Deprecations and Removals: - (SEMVER-MAJOR) fs: runtime deprecate string coercion in `fs.write`, `fs.writeFileSync` (Livia Medeiros) (https://github.com/nodejs/node/pull/42607) - (SEMVER-MAJOR) dns: remove `dns.lookup` and `dnsPromises.lookup` options type coercion (Antoine du Hamel) (https://github.com/nodejs/node/pull/41431) - (SEMVER-MAJOR) process: runtime deprecate multipleResolves (Benjamin Gruenbaum) (https://github.com/nodejs/node/pull/41896) - (SEMVER-MAJOR) stream: remove thenable support (Robert Nagy) (https://github.com/nodejs/node/pull/40773) - (SEMVER-MAJOR) tls: move tls.parseCertString to end-of-life (Tobias Nießen) (https://github.com/nodejs/node/pull/41479) fetch (experimental): An experimental fetch API is available on the global scope by default. The implementation is based upon https://undici.nodejs.org/#/, an HTTP/1.1 client written for Node.js by contributors to the project. Through this addition, the following globals are made available: `fetch` , `FormData`, `Headers`, `Request`, `Response`. Disable this API with the `--no-experimental-fetch` command-line flag. Contributed by Michaël Zasso in https://github.com/nodejs/node/pull/41811. HTTP Timeouts: `server.headersTimeout`, which limits the amount of time the parser will wait to receive the complete HTTP headers, is now set to `60000` (60 seconds) by default. `server.requestTimeout`, which sets the timeout value in milliseconds for receiving the entire request from the client, is now set to `300000` (5 minutes) by default. If these timeouts expire, the server responds with status 408 without forwarding the request to the request listener and then closes the connection. Both timeouts must be set to a non-zero value to protect against potential Denial-of-Service attacks in case the server is deployed without a reverse proxy in front. Contributed by Paolo Insogna in https://github.com/nodejs/node/pull/41263. Test Runner module (experimental): The `node:test` module facilitates the creation of JavaScript tests that report results in TAP format. This module is only available under the `node:` scheme. Contributed by Colin Ihrig in https://github.com/nodejs/node/pull/42325. Toolchain and Compiler Upgrades: - Prebuilt binaries for Linux are now built on Red Hat Enterprise Linux (RHEL) 8 and are compatible with Linux distributions based on glibc 2.28 or later, for example, Debian 10, RHEL 8, Ubuntu 20.04. - Prebuilt binaries for macOS now require macOS 10.15 or later. - For AIX the minimum supported architecture has been raised from Power 7 to Power 8. Prebuilt binaries for 32-bit Windows will initially not be available due to issues building the V8 dependency in Node.js. We hope to restore 32-bit Windows binaries for Node.js 18 with a future V8 update. Node.js does not support running on operating systems that are no longer supported by their vendor. For operating systems where their vendor has planned to end support earlier than April 2025, such as Windows 8.1 (January 2023) and Windows Server 2012 R2 (October 2023), support for Node.js 18 will end at the earlier date. Full details about the supported toolchains and compilers are documented in the Node.js `BUILDING.md` file. Contributed by Richard Lau in https://github.com/nodejs/node/pull/42292, https://github.com/nodejs/node/pull/42604 and https://github.com/nodejs/node/pull/42659 , and Michaël Zasso in https://github.com/nodejs/node/pull/42105 and https://github.com/nodejs/node/pull/42666. V8 10.1: The V8 engine is updated to version 10.1, which is part of Chromium 101. Compared to the version included in Node.js 17.9.0, the following new features are included: - The `findLast` and `findLastIndex` array methods. - Improvements to the `Intl.Locale` API. - The `Intl.supportedValuesOf` function. - Improved performance of class fields and private class methods (the initialization of them is now as fast as ordinary property stores). The data format returned by the serialization API (`v8.serialize(value)`) has changed, and cannot be deserialized by earlier versions of Node.js. On the other hand, it is still possible to deserialize the previous format, as the API is backwards-compatible. Contributed by Michaël Zasso in https://github.com/nodejs/node/pull/42657. Web Streams API (experimental): Node.js now exposes the experimental implementation of the Web Streams API on the global scope. This means the following APIs are now globally available: - `ReadableStream`, `ReadableStreamDefaultReader`, `ReadableStreamBYOBReader`, `ReadableStreamBYOBRequest`, `ReadableByteStreamController`, `ReadableStreamDefaultController`, `TransformStream`, `TransformStreamDefaultController`, `WritableStream`, `WritableStreamDefaultWriter`, `WritableStreamDefaultController`, `ByteLengthQueuingStrategy`, `CountQueuingStrategy`, `TextEncoderStream`, `TextDecoderStream`, `CompressionStream`, `DecompressionStream`. Contributed James Snell in https://github.com/nodejs/node/pull/39062, and Antoine du Hamel in https://github.com/nodejs/node/pull/42225. Other Notable Changes: - (SEMVER-MAJOR) buffer: expose Blob as a global (James M Snell) (https://github.com/nodejs/node/pull/41270) - (SEMVER-MAJOR) child\_process: improve argument validation (Rich Trott) (https://github.com/nodejs/node/pull/41305) - doc: add RafaelGSS to collaborators (RafaelGSS) (https://github.com/nodejs/node/pull/42718) - (SEMVER-MAJOR) http: make TCP noDelay enabled by default (Paolo Insogna) (https://github.com/nodejs/node/pull/42163) - (SEMVER-MAJOR) net: make `server.address()` return an integer for `family` (Antoine du Hamel) (https://github.com/nodejs/node/pull/41431) - (SEMVER-MAJOR) worker: expose BroadcastChannel as a global (James M Snell) (https://github.com/nodejs/node/pull/41271) - (SEMVER-MAJOR) worker: graduate BroadcastChannel to supported (James M Snell) (https://github.com/nodejs/node/pull/41271) Semver-Major Commits: - (SEMVER-MAJOR) assert,util: compare RegExp.lastIndex while using deep equal checks (Ruben Bridgewater) (https://github.com/nodejs/node/pull/41020) - (SEMVER-MAJOR) buffer: refactor `byteLength` to remove outdated optimizations (Rongjian Zhang) (https://github.com/nodejs/node/pull/38545) - (SEMVER-MAJOR) buffer: expose Blob as a global (James M Snell) (https://github.com/nodejs/node/pull/41270) - (SEMVER-MAJOR) buffer: graduate Blob from experimental (James M Snell) (https://github.com/nodejs/node/pull/41270) - (SEMVER-MAJOR) build: make x86 Windows support temporarily experimental (Michaël Zasso) (https://github.com/nodejs/node/pull/42666) - (SEMVER-MAJOR) build: bump macOS deployment target to 10.15 (Richard Lau) (https://github.com/nodejs/node/pull/42292) - (SEMVER-MAJOR) build: downgrade Windows 8.1 and server 2012 R2 to experimental (Michaël Zasso) (https://github.com/nodejs/node/pull/42105) - (SEMVER-MAJOR) child\_process: improve argument validation (Rich Trott) (https://github.com/nodejs/node/pull/41305) - (SEMVER-MAJOR) cluster: make `kill` to be just `process.kill` (Bar Admoni) (https://github.com/nodejs/node/pull/34312) - (SEMVER-MAJOR) crypto: cleanup validation (Mohammed Keyvanzadeh) (https://github.com/nodejs/node/pull/39841) - (SEMVER-MAJOR) crypto: prettify othername in PrintGeneralName (Tobias Nießen) (https://github.com/nodejs/node/pull/42123) - (SEMVER-MAJOR) crypto: fix X509Certificate toLegacyObject (Tobias Nießen) (https://github.com/nodejs/node/pull/42124) - (SEMVER-MAJOR) crypto: use RFC2253 format in PrintGeneralName (Tobias Nießen) (https://github.com/nodejs/node/pull/42002) - (SEMVER-MAJOR) crypto: change default check(Host|Email) behavior (Tobias Nießen) (https://github.com/nodejs/node/pull/41600) - (SEMVER-MAJOR) deps: V8: cherry-pick semver-major commits from 10.2 (Michaël Zasso) (https://github.com/nodejs/node/pull/42657) - (SEMVER-MAJOR) deps: update V8 to 10.1.124.6 (Michaël Zasso) (https://github.com/nodejs/node/pull/42657) - (SEMVER-MAJOR) deps: update V8 to 9.8.177.9 (Michaël Zasso) (https://github.com/nodejs/node/pull/41610) - (SEMVER-MAJOR) deps: update V8 to 9.7.106.18 (Michaël Zasso) (https://github.com/nodejs/node/pull/40907) - (SEMVER-MAJOR) dns: remove `dns.lookup` and `dnsPromises.lookup` options type coercion (Antoine du Hamel) (https://github.com/nodejs/node/pull/41431) - (SEMVER-MAJOR) doc: update minimum glibc requirements for Linux (Richard Lau) (https://github.com/nodejs/node/pull/42659) - (SEMVER-MAJOR) doc: update AIX minimum supported arch (Richard Lau) (https://github.com/nodejs/node/pull/42604) - (SEMVER-MAJOR) fs: runtime deprecate string coercion in `fs.write`, `fs.writeFileSync` (Livia Medeiros) (https://github.com/nodejs/node/pull/42607) - (SEMVER-MAJOR) http: refactor headersTimeout and requestTimeout logic (Paolo Insogna) (https://github.com/nodejs/node/pull/41263) - (SEMVER-MAJOR) http: make TCP noDelay enabled by default (Paolo Insogna) (https://github.com/nodejs/node/pull/42163) - (SEMVER-MAJOR) lib: enable fetch by default (Michaël Zasso) (https://github.com/nodejs/node/pull/41811) - (SEMVER-MAJOR) lib: replace validator and error (Mohammed Keyvanzadeh) (https://github.com/nodejs/node/pull/41678) - (SEMVER-MAJOR) module,repl: support 'node:'-only core modules (Colin Ihrig) (https://github.com/nodejs/node/pull/42325) - (SEMVER-MAJOR) net: make `server.address()` return an integer for `family` (Antoine du Hamel) (https://github.com/nodejs/node/pull/41431) - (SEMVER-MAJOR) process: disallow some uses of Object.defineProperty() on process.env (Himself65) (https://github.com/nodejs/node/pull/28006) - (SEMVER-MAJOR) process: runtime deprecate multipleResolves (Benjamin Gruenbaum) (https://github.com/nodejs/node/pull/41896) - (SEMVER-MAJOR) readline: fix question still called after closed (Xuguang Mei) (https://github.com/nodejs/node/pull/42464) - (SEMVER-MAJOR) stream: remove thenable support (Robert Nagy) (https://github.com/nodejs/node/pull/40773) - (SEMVER-MAJOR) stream: expose web streams globals, remove runtime experimental warning (Antoine du Hamel) (https://github.com/nodejs/node/pull/42225) - (SEMVER-MAJOR) stream: need to cleanup event listeners if last stream is readable (Xuguang Mei) (https://github.com/nodejs/node/pull/41954) - (SEMVER-MAJOR) stream: revert revert `map` spec compliance (Benjamin Gruenbaum) (https://github.com/nodejs/node/pull/41933) - (SEMVER-MAJOR) stream: throw invalid arg type from End Of Stream (Jithil P Ponnan) (https://github.com/nodejs/node/pull/41766) - (SEMVER-MAJOR) stream: don't emit finish after destroy (Robert Nagy) (https://github.com/nodejs/node/pull/40852) - (SEMVER-MAJOR) stream: add errored and closed props (Robert Nagy) (https://github.com/nodejs/node/pull/40696) - (SEMVER-MAJOR) test: add initial test module (Colin Ihrig) (https://github.com/nodejs/node/pull/42325) - (SEMVER-MAJOR) timers: refactor internal classes to ES2015 syntax (Rabbit) (https://github.com/nodejs/node/pull/37408) - (SEMVER-MAJOR) tls: represent registeredID numerically always (Tobias Nießen) (https://github.com/nodejs/node/pull/41561) - (SEMVER-MAJOR) tls: move tls.parseCertString to end-of-life (Tobias Nießen) (https://github.com/nodejs/node/pull/41479) - (SEMVER-MAJOR) url: throw on NULL in IPv6 hostname (Rich Trott) (https://github.com/nodejs/node/pull/42313) - (SEMVER-MAJOR) v8: make v8.writeHeapSnapshot() error codes consistent (Darshan Sen) (https://github.com/nodejs/node/pull/42577) - (SEMVER-MAJOR) v8: make writeHeapSnapshot throw if fopen fails (Antonio Román) (https://github.com/nodejs/node/pull/41373) - (SEMVER-MAJOR) worker: expose BroadcastChannel as a global (James M Snell) (https://github.com/nodejs/node/pull/41271) - (SEMVER-MAJOR) worker: graduate BroadcastChannel to supported (James M Snell) (https://github.com/nodejs/node/pull/41271) PR-URL: https://github.com/nodejs/node/pull/42262
18 KiB
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.
const ac = new AbortController();
ac.signal.addEventListener('abort', () => console.log('Aborted!'),
{ once: true });
ac.abort();
console.log(ac.signal.aborted); // Prints True
abortController.abort([reason])
reason{any} An optional reason, retrievable on theAbortSignalsreasonproperty.
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([reason])
reason: {any}- Returns: {AbortSignal}
Returns a new already aborted AbortSignal.
Static method: AbortSignal.timeout(delay)
delay{number} The number of milliseconds to wait before triggering the AbortSignal.
Returns a new AbortSignal which will be aborted in delay milliseconds.
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.
abortSignal.reason
- Type: {any}
An optional reason specified when the AbortSignal was triggered.
const ac = new AbortController();
ac.abort(new Error('boom!'));
console.log(ac.signal.reason); // Error('boom!');
abortSignal.throwIfAborted()
If abortSignal.aborted is true, throws abortSignal.reason.
Class: Blob
See {Blob}.
Class: Buffer
- {Function}
Used to handle binary data. See the buffer section.
Class: ByteLengthQueuingStrategy
Stability: 1 - Experimental.
A browser-compatible implementation of ByteLengthQueuingStrategy.
__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.
atob(data)
Stability: 3 - Legacy. Use
Buffer.from(data, 'base64')instead.
Global alias for buffer.atob().
BroadcastChannel
See {BroadcastChannel}.
btoa(data)
Stability: 3 - Legacy. Use
buf.toString('base64')instead.
Global alias for buffer.btoa().
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.
Class: CompressionStream
Stability: 1 - Experimental.
A browser-compatible implementation of CompressionStream.
console
- {Object}
Used to print to stdout and stderr. See the console section.
Class: CountQueuingStrategy
Stability: 1 - Experimental.
A browser-compatible implementation of CountQueuingStrategy.
Crypto
Stability: 1 - Experimental. Enable this API with the
--experimental-global-webcryptoCLI flag.
A browser-compatible implementation of {Crypto}. This global is available
only if the Node.js binary was compiled with including support for the
crypto module.
crypto
Stability: 1 - Experimental. Enable this API with the
--experimental-global-webcryptoCLI flag.
A browser-compatible implementation of the Web Crypto API.
CryptoKey
Stability: 1 - Experimental. Enable this API with the
--experimental-global-webcryptoCLI flag.
A browser-compatible implementation of {CryptoKey}. This global is available
only if the Node.js binary was compiled with including support for the
crypto module.
Class: DecompressionStream
Stability: 1 - Experimental.
A browser-compatible implementation of DecompressionStream.
Event
A browser-compatible implementation of the Event class. See
EventTarget and Event API for more details.
EventTarget
A browser-compatible implementation of the EventTarget class. See
EventTarget and Event API for more details.
exports
This variable may appear to be global but is not. See exports.
fetch
Stability: 1 - Experimental. Disable this API with the
--no-experimental-fetchCLI flag.
A browser-compatible implementation of the fetch() function.
Class FormData
Stability: 1 - Experimental. Disable this API with the
--no-experimental-fetchCLI flag.
A browser-compatible implementation of {FormData}.
global
- {Object} The global namespace object.
In browsers, the top-level scope is the global scope. This means that
within the browser var something will define a new global variable. In
Node.js this is different. The top-level scope is not the global scope;
var something inside a Node.js module will be local to that module.
Class Headers
Stability: 1 - Experimental. Disable this API with the
--no-experimental-fetchCLI flag.
A browser-compatible implementation of {Headers}.
MessageChannel
The MessageChannel class. See MessageChannel for more details.
MessageEvent
The MessageEvent class. See MessageEvent for more details.
MessagePort
The MessagePort class. See MessagePort for more details.
module
This variable may appear to be global but is not. See module.
performance
The perf_hooks.performance object.
process
- {Object}
The process object. See the process object section.
queueMicrotask(callback)
callback{Function} Function to be queued.
The queueMicrotask() method queues a microtask to invoke callback. If
callback throws an exception, the process object 'uncaughtException'
event will be emitted.
The microtask queue is managed by V8 and may be used in a similar manner to
the process.nextTick() queue, which is managed by Node.js. The
process.nextTick() queue is always processed before the microtask queue
within each turn of the Node.js event loop.
// Here, `queueMicrotask()` is used to ensure the 'load' event is always
// emitted asynchronously, and therefore consistently. Using
// `process.nextTick()` here would result in the 'load' event always emitting
// before any other promise jobs.
DataHandler.prototype.load = async function load(key) {
const hit = this._cache.get(key);
if (hit !== undefined) {
queueMicrotask(() => {
this.emit('load', hit);
});
return;
}
const data = await fetchData(key);
this._cache.set(key, data);
this.emit('load', data);
};
Class: ReadableByteStreamController
Stability: 1 - Experimental.
A browser-compatible implementation of ReadableByteStreamController.
Class: ReadableStream
Stability: 1 - Experimental.
A browser-compatible implementation of ReadableStream.
Class: ReadableStreamBYOBReader
Stability: 1 - Experimental.
A browser-compatible implementation of ReadableStreamBYOBReader.
Class: ReadableStreamBYOBRequest
Stability: 1 - Experimental.
A browser-compatible implementation of ReadableStreamBYOBRequest.
Class: ReadableStreamDefaultController
Stability: 1 - Experimental.
A browser-compatible implementation of ReadableStreamDefaultController.
Class: ReadableStreamDefaultReader
Stability: 1 - Experimental.
A browser-compatible implementation of ReadableStreamDefaultReader.
require()
This variable may appear to be global but is not. See require().
Response
Stability: 1 - Experimental. Disable this API with the
--no-experimental-fetchCLI flag.
A browser-compatible implementation of {Response}.
Request
Stability: 1 - Experimental. Disable this API with the
--no-experimental-fetchCLI flag.
A browser-compatible implementation of {Request}.
setImmediate(callback[, ...args])
setImmediate is described in the timers section.
setInterval(callback, delay[, ...args])
setInterval is described in the timers section.
setTimeout(callback, delay[, ...args])
setTimeout is described in the timers section.
structuredClone(value[, options])
The WHATWG structuredClone method.
SubtleCrypto
Stability: 1 - Experimental. Enable this API with the
--experimental-global-webcryptoCLI flag.
A browser-compatible implementation of {SubtleCrypto}. This global is available
only if the Node.js binary was compiled with including support for the
crypto module.
DOMException
The WHATWG DOMException class. See DOMException for more details.
TextDecoder
The WHATWG TextDecoder class. See the TextDecoder section.
Class: TextDecoderStream
Stability: 1 - Experimental.
A browser-compatible implementation of TextDecoderStream.
TextEncoder
The WHATWG TextEncoder class. See the TextEncoder section.
Class: TextEncoderStream
Stability: 1 - Experimental.
A browser-compatible implementation of TextEncoderStream.
Class: TransformStream
Stability: 1 - Experimental.
A browser-compatible implementation of TransformStream.
Class: TransformStreamDefaultController
Stability: 1 - Experimental.
A browser-compatible implementation of TransformStreamDefaultController.
URL
The WHATWG URL class. See the URL section.
URLSearchParams
The WHATWG URLSearchParams class. See the URLSearchParams section.
WebAssembly
- {Object}
The object that acts as the namespace for all W3C WebAssembly related functionality. See the Mozilla Developer Network for usage and compatibility.
Class: WritableStream
Stability: 1 - Experimental.
A browser-compatible implementation of WritableStream.
Class: WritableStreamDefaultController
Stability: 1 - Experimental.
A browser-compatible implementation of WritableStreamDefaultController.
Class: WritableStreamDefaultWriter
Stability: 1 - Experimental.
A browser-compatible implementation of WritableStreamDefaultWriter.