Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

API reference

Node.js API reference

Node.js, APIs and backend architecture

Identifiers
108
With full guides
83
Types
5

Topics covered

  • Event loop
  • Streams & backpressure
  • Worker threads
  • Clustering
  • Error handling
  • EventEmitter
  • Buffers
  • Native test runner

Class

NameWhat it does
BufferBuffer represents a fixed-length sequence of bytes in Node.js. It extends Uint8Array with methods for creating, transforming, reading, and writing binary data.
EventEmitterEventEmitter is Node.js’s base class for named, synchronous event dispatch. Register listeners with on() or once(), then trigger them with emit(), passing optional arguments.
ReadableClass
WritableClass
TransformThe stream.Transform class is a Duplex stream whose readable output is computed from writable input. Custom transforms implement _transform() and may implement _flush() for final processing.
Duplexstream.Duplex is a bidirectional stream that implements both the Readable and Writable interfaces. Extend it or construct it with callbacks to define how data is read and written.
AbortControllerAbortController signals cancellation to selected Promise-based APIs. Pass its signal to an operation and call abort() to trigger cancellation notification.
URLThe WHATWG URL class parses absolute URLs and resolves relative references against a base URL. It exposes structured URL components and serializes them back into standard URL strings.
ServerClass
ClientRequesthttp.ClientRequest is the writable stream representing an in-progress HTTP client request. It is returned by http.request(), accepts request data and headers, and emits the server response when response headers arrive.
ServerResponseClass
IncomingMessagehttp.IncomingMessage is the readable-stream object Node.js provides for an incoming HTTP request or client response. It exposes HTTP metadata and carries the message body.
URLSearchParamsURLSearchParams is a mutable collection for reading and changing URL query parameters. It can be constructed independently or from query data associated with a URL.
AbortSignalAbortSignal is an EventTarget-based cancellation signal for selected promise APIs. It can be created in an aborted, timed, or composed form and exposes cancellation state and reason.
WorkerClass
MessageChannelMessageChannel creates an asynchronous, bidirectional communication channel in Node.js. Its two linked MessagePort endpoints let code exchange messages within a thread or across workers.
MessagePortMessagePort is one endpoint of an asynchronous, two-way channel in Node.js worker_threads. It sends structured-clone data and can transfer memory regions or other MessagePort instances between workers.
BlobBlob encapsulates immutable raw data that can be safely shared across worker threads. It combines string or binary parts and supports byte, text, ArrayBuffer, and stream-based reads.
TextEncoderClass
TextDecoderTextDecoder implements the WHATWG Encoding Standard API for converting encoded binary data into JavaScript strings. It supports configurable encodings, streaming chunks, malformed-input handling, and byte-order-mark behavior.
AsyncLocalStorageAsyncLocalStorage maintains context-specific state across asynchronous callbacks and promise chains. Use run() or enterWith() to establish a store and getStore() to retrieve it.

Function

NameWhat it does
pipelinestream.pipeline() connects a source through optional transforms to a destination, forwarding data, errors, and cleanup. It also handles backpressure and has a promise-based API.
setImmediateSchedules a callback after I/O callbacks, returning an Immediate handle that can be canceled with clearImmediate(). Multiple immediates execute in creation order.
setIntervalsetInterval repeatedly invokes a callback at a specified millisecond delay. It returns a Timeout handle that can be passed to clearInterval to stop future invocations.
fetchNode.js provides a browser-compatible global fetch() for making HTTP requests. It returns a promise for a Response, whose status and body can be inspected asynchronously.
requireFunction
structuredCloneFunction
queueMicrotaskQueues a callback as a V8 microtask for asynchronous execution after the current code completes. Node processes process.nextTick() callbacks before this microtask queue within an event-loop turn.
promisifyConverts an error-first callback-style function into a function that returns Promises. A custom implementation can override the default conversion.
readFilefs.readFile() asynchronously reads an entire file into memory and reports completion through a callback. It returns text when an encoding is supplied; otherwise it returns a Buffer.
writeFileAsynchronously writes data to a file, replacing existing contents by default. It accepts strings, Buffers, and iterable data, with options for encoding, permissions, and opening behavior.
readFileSyncreadFileSync() synchronously reads an entire file and returns its contents. It yields a Buffer by default or a string when an encoding is selected.
createServerFunction
createHashFunction
createHmacCreates an Hmac object configured with a digest algorithm and secret key. Use the returned object to update data and produce the HMAC digest.
randomUUIDFunction
spawnchild_process.spawn() starts a new process asynchronously and returns a ChildProcess object. Supply the executable, optional argument tokens, and optional process settings.
execRuns a command through a shell and buffers its stdout and stderr until completion. It reports results through a callback or, when promisified, a Promise.
execSyncexecSync executes a shell command and waits synchronously for the child process to close. It returns standard output or throws when execution times out or the command exits unsuccessfully.
forkchild_process.fork() starts a new Node.js process to run a specified module and provides a built-in IPC channel for parent-child communication. It returns a ChildProcess instance.
createReadStreamCreates a readable stream for a file, allowing data to be consumed incrementally. Options can select encoding, byte ranges, buffering, and file-descriptor behavior.
createWriteStreamCreates and returns a writable stream connected to a file. Use it to write data incrementally while controlling file-opening behavior through options.

Const

NameWhat it does
processprocess is a Node.js global object representing the currently running process. It exposes runtime information, environment data, command-line arguments, and process control APIs.
consoleNode.js's global console is a built-in debugging logger. It provides familiar logging methods and is preconfigured to write normal output and errors to the process standard streams.
globalThisglobalThis is Node.js’s standard reference to the global namespace object. It is available across modules, while top-level module variables remain module-local.
performanceNode.js’s performance object provides high-resolution timing and Performance Timeline operations for measuring code and inspecting runtime metrics.

Module

NameWhat it does
fsThe node:fs module provides Node.js access to files and directories through synchronous, callback-based, and promise-based APIs. It is suited to reading, writing, opening, inspecting, and streaming filesystem data.
httpNode.js's node:http module provides low-level HTTP client and server APIs. It streams request and response data instead of buffering complete messages, leaving application-level parsing and routing to the caller.
pathNode.js's node:path module provides platform-aware utilities for manipulating file and directory path strings. It supports construction, normalization, inspection, absolute resolution, relative-path calculation, and explicit POSIX or Windows behavior.
streamNode.js streams are abstractions for processing data incrementally. The node:stream module defines readable, writable, duplex, and transform stream types plus callback- and Promise-oriented utilities.
cryptoNode.js node:crypto provides OpenSSL-backed APIs for hashing, HMAC, encryption, decryption, signing, verification, randomness, and key management. Its operation-specific objects consume data and produce a final result.
worker_threadsNode.js worker_threads runs JavaScript in parallel worker threads, primarily for CPU-intensive tasks. Workers communicate through message ports and can transfer or share memory.
clusterThe cluster module runs multiple Node.js processes that share server ports, allowing incoming connections and application work to be distributed among workers. A primary process creates and supervises workers, which communicate with it through IPC.
osThe node:os module provides synchronous utilities and constants for inspecting the operating system, CPU, memory, directories, network interfaces, and runtime environment. It is available through ES module and CommonJS imports.
utilThe node:util module provides built-in helpers for Node.js internals and application code. It includes formatting, inspection, debugging, type checks, and other common utility APIs.
child_processThe node:child_process module lets Node.js start subprocesses asynchronously or synchronously. Its APIs cover direct executable launching, shell commands, Node.js worker processes, and parent-child IPC.
netThe node:net module provides asynchronous, stream-based networking for TCP and IPC. It supplies APIs for creating servers and clients that communicate through sockets.
dnsModule
zlibModule
readlineNode.js readline provides line-by-line access to a Readable stream, including process.stdin. Its promise-based API supports interactive questions with async/await.
assertModule
node:fsModule
node:fs/promisesModule
node:pathThe node:path module provides utilities for manipulating file and directory path strings. Its default methods follow the host platform, while path.posix and path.win32 provide explicit platform-specific behavior.
node:httpModule
node:httpsnode:https provides Node.js client and server APIs for HTTP over TLS/SSL. It supports secure requests, HTTPS servers, connection agents, and TLS-specific configuration.
node:osThe node:os module provides synchronous utilities and constants for inspecting the operating system around a Node.js process. It exposes host identity, CPU and memory information, directories, network interfaces, load, uptime, and platform conventions.
node:cryptoThe node:crypto module provides Node.js access to cryptographic operations including hashes, HMACs, encryption, decryption, signing, and verification. Its APIs wrap functionality supplied by OpenSSL.
node:eventsNode.js's node:events module provides EventEmitter for named, synchronous notifications. Register persistent or one-time listeners, emit events with arguments, and remove listeners when they are no longer needed.
node:streamThe node:stream module provides abstractions and utilities for processing data incrementally. It includes Readable, Writable, Duplex, and Transform stream types plus callback- and Promise-based composition APIs.
node:stream/promisesnode:stream/promises provides promise-returning utilities for working with streams. Use it with async/await to compose pipelines and await stream completion instead of supplying callbacks.
node:bufferThe node:buffer module provides Buffer, Node.js’s fixed-length byte sequence for handling binary data. It extends Uint8Array and supports safe allocation, conversion, encoding, and byte-level operations.
node:utilThe node:util module provides general-purpose helpers used by Node.js internals and application developers. Its APIs cover debugging inspection, formatting, type checks, and other runtime utilities.
node:urlThe node:url module supplies URL parsing, resolution, construction, and query-string utilities. Prefer its WHATWG-compatible URL and URLSearchParams APIs for new code; the module also retains a deprecated legacy API.
node:querystringThe node:querystring module parses URL query strings into key-value collections and formats objects back into query-string text. It also exposes encoding and decoding helpers.
node:zlibModule
node:child_processThe node:child_process module launches external commands and Node.js subprocesses. It offers asynchronous and synchronous APIs, stream-based process control, shell command execution, and IPC for forked Node.js processes.
node:clusterThe node:cluster module creates multiple Node.js worker processes that can share server ports. A primary process manages workers and can distribute incoming connections among them.
node:worker_threadsnode:worker_threads runs JavaScript in parallel in independent threads, making it suitable for CPU-intensive work. Workers communicate through message ports and can transfer or share memory buffers.
node:netNode.js’s node:net module provides asynchronous, stream-based TCP and IPC networking. Use it to create servers with net.createServer() and clients with net.createConnection() or net.connect().
node:dnsThe node:dns module provides APIs for resolving host names, IP addresses, and DNS records. Choose dns.lookup() for operating-system resolution or DNS resolver methods when querying DNS records directly.
node:tlsThe node:tls module provides OpenSSL-backed TLS and SSL networking for Node.js clients and servers. It includes encrypted sockets, TLS servers, secure contexts, certificate handling, and protocol inspection.
node:readlineModule
node:processModule
node:timersNode.js timers schedule callbacks for later execution through the event loop. Use setTimeout, setInterval, or setImmediate, and cancel scheduled work with the matching clear function.
node:assertThe node:assert module provides built-in assertion functions for checking invariants. Prefer the strict entry point for non-coercive equality and deep comparisons.
node:vmThe node:vm module compiles and runs JavaScript in V8 Virtual Machine contexts. It supports direct execution, reusable vm.Script objects, and low-level ECMAScript module execution.
node:perf_hooksnode:perf_hooks provides browser-compatible performance APIs and Node.js-specific measurements. It supports high-resolution timing, user and resource timing, observers, function instrumentation, and event-loop utilization.
node:async_hooksModule
node:diagnostics_channelnode:diagnostics_channel provides named channels for sending arbitrary diagnostic data. Producers can publish efficiently when subscribers exist, while consumers attach and remove message handlers.
node:testnode:test is Node.js’s built-in test module. Define synchronous, Promise-based, or callback-based tests and run them with the Node.js test runner.
node:dgramnode:dgram provides UDP datagram sockets. Create a socket, bind it to receive message events, send datagrams, and close it when finished.
node:string_decoderThe node:string_decoder module decodes Buffer chunks into text without breaking multi-byte UTF-8 or UTF-16 characters across chunk boundaries. StringDecoder buffers incomplete sequences until later input completes them.
node:v8Module
node:moduleModule
node:consoleThe node:console module provides a global console and a configurable Console class for debugging and logging. Custom instances can direct regular output and errors to chosen writable streams.

Pipe

NameWhat it does
process.envprocess.env is Node.js’s object for reading and changing environment variables available to the current process. Values assigned to it become strings, and worker threads normally receive separate copies.
process.argvPipe
process.cwdprocess.cwd() returns the current working directory of the Node.js process as a string. It takes no arguments.
process.platformprocess.platform is a read-only string identifying the operating-system platform for which the Node.js binary was compiled. Common values include linux, darwin, win32, and other documented platform identifiers.
process.pidPipe
process.versionprocess.version is a string containing the version of the running Node.js runtime. It includes a leading v; use process.versions.node for the version without that prefix.
process.nextTickprocess.nextTick() defers a callback until the current JavaScript operation finishes, then runs it before the event loop continues. It can also pass extra arguments to that callback.
__dirname__dirname is a CommonJS module-local string containing the directory of the currently executing script. Use it to build paths anchored to that module instead of the process's working directory.
__filename__filename is a CommonJS module variable containing the current module’s absolute file path, with symbolic links resolved. It is module-local, not a true global.
module.exportsmodule.exports defines the value a CommonJS module exposes to callers. Assign an object, function, or other value to it, and require() receives that value.
require.resolverequire.resolve() finds the filename CommonJS require() would load without loading the module. It returns a string or throws MODULE_NOT_FOUND when resolution fails.
import.meta.urlimport.meta.url is the absolute file URL of the current ES module. Use it as the base for resolving nearby resources with URL-aware Node.js APIs.

Search across every package and filter by type in your dashboard.

Start learning