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
| Name | What it does |
|---|---|
Buffer | Buffer represents a fixed-length sequence of bytes in Node.js. It extends Uint8Array with methods for creating, transforming, reading, and writing binary data. |
EventEmitter | EventEmitter 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. |
Readable | |
Writable | |
Transform | The 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. |
Duplex | stream.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. |
AbortController | AbortController signals cancellation to selected Promise-based APIs. Pass its signal to an operation and call abort() to trigger cancellation notification. |
URL | The 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. |
Server | |
ClientRequest | http.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. |
ServerResponse | |
IncomingMessage | http.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. |
URLSearchParams | URLSearchParams is a mutable collection for reading and changing URL query parameters. It can be constructed independently or from query data associated with a URL. |
AbortSignal | AbortSignal 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. |
Worker | |
MessageChannel | MessageChannel creates an asynchronous, bidirectional communication channel in Node.js. Its two linked MessagePort endpoints let code exchange messages within a thread or across workers. |
MessagePort | MessagePort 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. |
Blob | Blob 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. |
TextEncoder | |
TextDecoder | TextDecoder 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. |
AsyncLocalStorage | AsyncLocalStorage maintains context-specific state across asynchronous callbacks and promise chains. Use run() or enterWith() to establish a store and getStore() to retrieve it. |
Function
| Name | What it does |
|---|---|
pipeline | stream.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. |
setImmediate | Schedules a callback after I/O callbacks, returning an Immediate handle that can be canceled with clearImmediate(). Multiple immediates execute in creation order. |
setInterval | setInterval repeatedly invokes a callback at a specified millisecond delay. It returns a Timeout handle that can be passed to clearInterval to stop future invocations. |
fetch | Node.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. |
require | |
structuredClone | |
queueMicrotask | Queues 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. |
promisify | Converts an error-first callback-style function into a function that returns Promises. A custom implementation can override the default conversion. |
readFile | fs.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. |
writeFile | Asynchronously 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. |
readFileSync | readFileSync() synchronously reads an entire file and returns its contents. It yields a Buffer by default or a string when an encoding is selected. |
createServer | |
createHash | |
createHmac | Creates an Hmac object configured with a digest algorithm and secret key. Use the returned object to update data and produce the HMAC digest. |
randomUUID | |
spawn | child_process.spawn() starts a new process asynchronously and returns a ChildProcess object. Supply the executable, optional argument tokens, and optional process settings. |
exec | Runs a command through a shell and buffers its stdout and stderr until completion. It reports results through a callback or, when promisified, a Promise. |
execSync | execSync 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. |
fork | child_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. |
createReadStream | Creates a readable stream for a file, allowing data to be consumed incrementally. Options can select encoding, byte ranges, buffering, and file-descriptor behavior. |
createWriteStream | Creates and returns a writable stream connected to a file. Use it to write data incrementally while controlling file-opening behavior through options. |
Const
| Name | What it does |
|---|---|
process | process is a Node.js global object representing the currently running process. It exposes runtime information, environment data, command-line arguments, and process control APIs. |
console | Node.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. |
globalThis | globalThis is Node.js’s standard reference to the global namespace object. It is available across modules, while top-level module variables remain module-local. |
performance | Node.js’s performance object provides high-resolution timing and Performance Timeline operations for measuring code and inspecting runtime metrics. |
Module
| Name | What it does |
|---|---|
fs | The 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. |
http | Node.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. |
path | Node.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. |
stream | Node.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. |
crypto | Node.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_threads | Node.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. |
cluster | The 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. |
os | The 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. |
util | The 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_process | The 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. |
net | The node:net module provides asynchronous, stream-based networking for TCP and IPC. It supplies APIs for creating servers and clients that communicate through sockets. |
dns | |
zlib | |
readline | Node.js readline provides line-by-line access to a Readable stream, including process.stdin. Its promise-based API supports interactive questions with async/await. |
assert | |
node:fs | |
node:fs/promises | |
node:path | The 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:http | |
node:https | node: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:os | The 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:crypto | The 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:events | Node.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:stream | The 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/promises | node: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:buffer | The 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:util | The 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:url | The 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:querystring | The 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:zlib | |
node:child_process | The 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:cluster | The 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_threads | node: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:net | Node.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:dns | The 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:tls | The 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:readline | |
node:process | |
node:timers | Node.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:assert | The node:assert module provides built-in assertion functions for checking invariants. Prefer the strict entry point for non-coercive equality and deep comparisons. |
node:vm | The 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_hooks | node: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_hooks | |
node:diagnostics_channel | node: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:test | node: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:dgram | node:dgram provides UDP datagram sockets. Create a socket, bind it to receive message events, send datagrams, and close it when finished. |
node:string_decoder | The 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:v8 | |
node:module | |
node:console | The 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
| Name | What it does |
|---|---|
process.env | process.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.argv | |
process.cwd | process.cwd() returns the current working directory of the Node.js process as a string. It takes no arguments. |
process.platform | process.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.pid | |
process.version | process.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.nextTick | process.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.exports | module.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.resolve | require.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.url | import.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