Other Node core modules
The smaller Node built-ins, grouped here rather than each given a full page. net, tls, http and https are Node's own layering ported to TypeScript — a net.Socket is a Duplex over a native TCP handle, a TLSSocket a Socket whose handle carries a non-blocking OpenSSL session, and http/https build on them — all on one event loop with dgram and dns. Messages across process and channel boundaries (cluster, diagnostics_channel) are strings, and vm stays out of scope behind the same blocker as bare eval().
querystring (.parse, .stringify, .escape, .unescape)
ExactNode's legacy "a=b&c=d" parse/stringify, ported from Node's own lib/querystring.js. parse returns a null-prototype object; a repeated key collects its values into an array; a leading '?' is plain text (unlike new URLSearchParams(str)). stringify takes an object whose array values repeat the key. Custom separators, maxKeys and custom encode/decode functions are honoured; escape, unescape, unescapeBuffer, encode and decode are exported too.
Parameters- str / objstring | ParsedUrlQueryInput
- A raw query tail to parse, or an object to serialize.
- sep, eqstring
- The pair and key/value separators ('&' and '=' by default).
ParsedUrlQuery | string — The parsed object, or the serialized query string.
const parsed = querystring.parse("topic=compilers%20and%20types&tag=a&tag=b")
console.log(parsed.topic) // compilers and types
console.log(parsed.tag) // [ 'a', 'b' ]assert (.ok, bare assert(cond, msg?), .equal/.strictEqual, .notEqual/.notStrictEqual, .deepEqual/.deepStrictEqual (+not*), .fail, .throws, .match/.doesNotMatch)
Works, with caveatsNode's assertion library, ported from Node's own sources: the same checks, the same AssertionError (name, code, actual, expected, operator), and the same failure messages and diffs, including assert.ok quoting the failing call's source. Distinct from console.assert, which logs and continues.
Returnsvoid — Nothing, or throws AssertionError.
assert.strictEqual("a" + "b", "ab")
assert.throws(() => { throw new Error("boom") })- No
assert.CallTracker(deprecated in Node) - Deep equality does not compare symbol-keyed properties, and a failure diff does not invoke getters
- An uncaught
AssertionErrorprintsUncaught: <message>rather than Node's name, stack and property block
test / node:test
Works, with caveatsNode's test runner: tests run after the module, one at a time in registration order, with describe/it suites, skip/todo, the TestContext (t.test, t.skip, t.todo, t.diagnostic, t.plan) and before/after/beforeEach/afterEach hooks, reported in Node's spec format with its summary and a nonzero exit on failure. The bare 'test' specifier is Node's own test-suite helpers: mustCall/mustCallAtLeast (counts checked at exit), mustSucceed, mustNotCall, expectsError, expectWarning, skip, and the platform probes.
ReturnsPromise<void> | T — Registration, or a counting wrapper of the callback.
- A failing test's details omit Node's
test at <file>:<line>:<col>line and the stack: the error prints asName [code]: message. - No
mock.*,run(), snapshots, concurrency, timeouts,t.signal/t.assert, oronlyfiltering. - The spec reporter prints without colors on a terminal (Node colors it); no other reporter.
util (.inspect, .format)
Works, with caveatsNode's util, ported from Node's own lib/util.js: format and formatWithOptions walk the specifiers at run time as Node does (%s calls a program's own toString), inspect takes depth, compact, sorted, breakLength and maxArrayLength, and callbackify, deprecate, debuglog, styleText, types and the system-error lookups behave as Node's.
Parameters- fmtstring
- A format string for .format (any string, at run time).
- valueany
- The value to render for .inspect.
string — The formatted/inspected string.
console.log(util.format("%s = %d", "count", 42))
console.log(util.inspect({ name: "kml", tags: ["ts", "native"] })).promisifywraps a function value and honourspromisify.custom; a code-generated builtin (fs.readFile) is not a function value to pass itpromisify(f) === fis false for an already-promisifiedf.inspectignorescolors,showHidden,getters,maxStringLengthandnumericSeparator;compact: trueis treated as 3; a custom method'sdepthargument isInfinity, notnull, when the depth is unlimited- No
inherits,MIMETypeorgetCallSites
net (TCP server: net.createServer, server.listen/address()/on('connection'|'listening')/close; TCP client: net.connect/createConnection (positional or { port, host }); connection socket .on('data'|'end')/.write/.end/.address()/.destroy()/.setNoDelay()/.setKeepAlive(); net.isIP/isIPv4/isIPv6)
Works, with caveatsNode's lib/net.js ported to TypeScript over native TCP handles on the event loop. A Socket is a Duplex — back-pressure and 'drain', pause/resume, setEncoding, setTimeout, ref/unref; Server listens by port/host/backlog/options or a Unix-socket path, dual-stack :: by default. Errors are built as Node builds them (connect ECONNREFUSED, getaddrinfo ENOTFOUND, with .code/.errno/.syscall/.address/.port).
Returnsnet.Server | net.Socket — A server or connection handle.
const server = net.createServer((socket) => {
socket.on('data', (chunk: Uint8Array) => { socket.write(chunk); });
});
server.listen(9099);connect/createConnectiontake a port, an options object or{ path }; the connect is non-blocking and a failure arrives as an async'error'then'close'listen's'listening'and'error'fire on the next tick, as in Node;maxConnectionsandgetConnectionsare supported;isIP/isIPv4/isIPv6- BlockList, SocketAddress and happy-eyeballs address selection (
autoSelectFamily) are not ported
dgram (UDP sockets: createSocket('udp4'), bind, address(), setBroadcast(), on('message'), send, close)
Works, with caveatsNode's UDP sockets: udp4/udp6, bind with 'listening', send in every form (offset/length, lists, before the bind completes), connect/disconnect, the broadcast/TTL/multicast options and group membership, buffer sizes, ref/unref. 'message' receives a Buffer and { address, family, port, size }.
Returnsdgram.Socket — A UDP socket handle.
const server = dgram.createSocket('udp4');
server.on('message', (msg, rinfo) => {
server.send('reply:' + msg.toString(), rinfo.port, rinfo.address);
});
server.bind(0, '127.0.0.1');- Sends are synchronous, so getSendQueueSize()/getSendQueueCount() are always 0.
- The lookup and block-list options, bind({ fd }) and cluster-shared sockets are not ported.
tls (TLS-wrapped sockets)
Works, with caveatsNode's _tls_wrap shape in TypeScript: a TLSSocket is a net.Socket whose handle carries a non-blocking OpenSSL session, so the handshake runs on the event loop. tls.connect supports servername, rejectUnauthorized, ca/cert/key and ALPN, firing 'secureConnect' with authorized/authorizationError and Node's verify error codes and messages; tls.createServer emits 'secureConnection' and 'tlsClientError'; createSecureContext, getProtocol and getCipher.
Returnstls.TLSSocket | tls.Server — A net-shaped TLS handle.
const sock = tls.connect(443, "example.com", () => {
sock.write("GET / HTTP/1.1\r\nHost: example.com\r\nConnection: close\r\n\r\n");
});
sock.on("data", (chunk: string) => { response += chunk; });- OpenSSL-only (libssl) — a
-crypto=commoncryptobuild usingtlsis a clean compile error (Mac's CommonCrypto has no TLS API) - Session resumption, OCSP, renegotiation, PSK and
getPeerCertificate()'s certificate object are not ported
dns (dns.lookup, dns.resolve4/resolve, dns.promises.lookup)
Works, with caveatsNode's own lib/dns.js. lookup and lookupService run getaddrinfo/getnameinfo on the thread pool, as libuv does (all, family, hints, order); the resolve family — resolve4/6 with TTLs, MX, TXT, SRV, NS, CNAME, PTR, SOA, NAPTR, CAA, TLSA, ANY, reverse — is Node's cares_wrap over c-ares: the system's servers, Resolver timeouts, tries, setServers, cancel and setLocalAddress, cares_wrap's record shapes, and Node's error codes (ENOTFOUND, ENODATA, ETIMEOUT, …). dns.promises and dns/promises are the promise forms.
Parameters- hoststring
- The hostname to resolve.
object | Promise<…> — The request (callbacks arrive on a later tick), or a Promise.
dns.lookup("localhost", (err, address, family) => {
console.log("localhost ->", address, "family", family);
});- A resolve error has no
errnokey (Node's haserrno: undefined)
zlib (gzip/gunzip, deflate/inflate, deflateRaw/inflateRaw, unzip, each *Sync + (err, result) callback)
Works, with caveatsNode's zlib module: the Deflate/Inflate/Gzip/Gunzip/DeflateRaw/InflateRaw/Unzip streams and their create* functions, the one-shot methods (callback and *Sync), crc32, constants and codes, with every zlib option. Each stream owns a native zlib handle whose writes run on the thread pool. Input may be a Buffer/TypedArray, ArrayBuffer, DataView, or string (UTF-8); output is always a Buffer.
Parameters- inputstring | Buffer | TypedArray | DataView | ArrayBuffer
- The data to compress or decompress.
- optionsZlibOptions
- flush, finishFlush, chunkSize, windowBits, level, memLevel, strategy, dictionary, info, maxOutputLength, rejectGarbageAfterEnd.
Buffer — The compressed/decompressed bytes (a stream for create*).
const gz = zlib.gzipSync(text)
console.log("gunzip:", dec.decode(zlib.gunzipSync(gz)) === text)
pipeline(Readable.from(parts), zlib.createGzip({ level: 6 }), zlib.createGunzip(), sink, done)- Brotli and Zstd load the system libbrotli/libzstd at run time (Node bundles them); where they are missing, a Brotli or Zstd stream is
ERR_ZLIB_INITIALIZATION_FAILED - Compressed bytes are the system libz's, which can differ from Node's bundled zlib at the same level (each inflates the other's)
- A
*Synccall withinfo: trueis typed{ buffer, engine }(@types types itBuffer)
vm (vm.Script, sandboxed eval-like execution)
Not supportedNot implemented. vm hits the same fundamental blocker as bare eval() — there is no embedded engine to run source assembled at runtime. An opt-in embedded-engine path is scoped but not started.
diagnostics_channel (channel/subscribe/unsubscribe/hasSubscribers/tracingChannel, Channel, TracingChannel)
fullNode's module: named channels whose subscribers receive any published value and the channel name; bound stores and runStores; tracing channels that publish start/end/asyncStart/asyncEnd/error around traceSync, tracePromise and traceCallback. A subscriber's throw is reported on the next tick without stopping the others.
ReturnsChannel | TracingChannel | boolean | void — A channel, a tracing channel, a subscription result, or nothing.
http client (http.get/http.request)
Works, with caveatsNode's _http_agent/_http_client in TypeScript over net. http.get and http.request return a ClientRequest (an OutgoingMessage) and the response is an IncomingMessage — a Readable.
ReturnsClientRequest — A request handle; the response arrives via callback.
- ClientRequest: chunked or
Content-Lengthbodies,'response'/'socket'/'information'/'upgrade'/'error',abort/destroy/setTimeout http.Agentpools keep-alive sockets;http.globalAgentkeeps them alive and unref'd, as Node 19+http.request(new URL(…))is not accepted — pass a string or an options object
https (client: https.get/https.request)
Works, with caveatshttps.createServer is a tls.Server running the http module's connection handling; https.request/get/Agent/globalAgent connect with tls.connect. Same request and response objects as http.
ReturnsClientRequest — A request handle; the response arrives via callback.
- Same client limit as
httpfor aURLargument
stream/web (re-exports: ReadableStream/WritableStream/TransformStream/CompressionStream/DecompressionStream)
ExactThe names bind as identity to the ambient WHATWG constructors that already exist — importing them from stream/web is interchangeable with using the globals. The queuing-strategy classes are not exported.
Returnstypeof ReadableStream — The same ambient constructors as the globals.
cluster (fork, worker messaging, isPrimary/isWorker/worker, Worker.id/.process)
Works, with caveatsNode's cluster module. The primary forks workers that run this same program; a worker's net or http server listens through the primary, which either accepts connections and hands them to the workers in turn (round-robin, the default outside Windows) or gives every worker the listening socket itself. Workers and the primary exchange messages, handles included, over the fork channel.
Returnscluster.Worker — A worker handle.
setupPrimary({ exec })naming another file fails atfork(): a worker is this compiled program, so there is no other script for it to runinspectPortand the inspector flags are ignored: a compiled program has no inspector- A
dgramsocket bound in a worker binds on its own, not through the primary - Windows: a worker's
listendoes not work yet — descriptor passing over the fork channel is POSIX-only
http2 **module** (http2.createServer/connect, Http2Session/Http2Stream)
Works, with caveatsNode's http2 module: HTTP/2 servers (cleartext h2c and TLS with ALPN, optionally answering HTTP/1.1) and client sessions, with the compat request/response API, the core stream API, push streams, settings, ping and goaway.
ReturnsHttp2Session | Http2Stream — A session or stream handle.
const server = http2.createServer();
server.on('stream', (stream, headers) => {
stream.respond({ ':status': 200, 'content-type': 'text/plain' });
stream.end("hello " + headers[':path'].slice(1));
});respondWithFD/respondWithFileread the whole file into memory before sending it, where Node streams itsession.altsvc()/origin()validate their arguments but send no frame;setNextStreamID/setLocalWindowSizevalidate onlysession.socketis the raw socket, not Node's Proxy guarding the session-owned socket methods- The
Http2ServerRequest/Http2ServerResponsesubclass options are ignored stream.writehas no backpressure: it always returnstrueand buffers- Most session tuning options (
maxSessionMemory,paddingStrategy, …) are accepted and ignored
async_hooks (AsyncLocalStorage, AsyncResource)
Works, with caveatsAsyncLocalStorage carries a store through an async call tree: run/exit/enterWith/getStore/disable and the name/defaultValue options, with the context frame propagating across await (a spawned task inherits it) and into promise reactions and timer, setImmediate, nextTick and queueMicrotask callbacks scheduled inside run(). Static bind/snapshot and AsyncResource (runInAsyncScope, bind) capture the current context and replay it later.
- createHook, executionAsyncId, triggerAsyncId and executionAsyncResource are not exported; asyncId() numbers resources in creation order with no lifecycle events behind it.