Pages

Topics

Tools

↑↓navigate↵openescclose

Node.js guides

Every published Node.js guide, newest first, with practical examples you can copy into your own project.

3,815 guides across 14 topics

Topics

Latest Node.js guides

3D illustration of an emitter horn broadcasting pulses to a ring of listeners with one leaking connection
Node.js

Node.js EventEmitter: once, error Events, and Listener Memory Leaks

emit is synchronous, so a throwing listener aborts the rest. An error event with no listener crashes the process, and a listener per request is the classic leak.

Node.jsEventsMemoryPatterns
3D illustration of data flowing through a hash funnel into a digest cube beside an AES chamber and key tiles
Node.js

Node.js crypto: Hashing, HMAC, AES-GCM, and Random Bytes

Hashing, HMAC, AES-256-GCM and randomness solve different problems. Never reuse a GCM nonce, never hash a password with sha256, and compare secrets with timingSafeEqual.

Node.jsCryptoSecurityEncryption
3D illustration of a server rack receiving request cards with an abort stop sign cutting a fetch arrow
Node.js

Node.js HTTP Server, Headers, AbortSignal, and Native fetch

Nothing is parsed for you: an unread body stalls the socket, and headers cannot change after the first write. fetch resolves on 404, and AbortSignal is the timeout mechanism.

Node.jsHTTPFetchServer
3D illustration of a main thread cube beside worker cubes sharing a memory grid slab
Node.js

Node.js worker_threads: SharedArrayBuffer and CPU Offloading

Each worker has its own isolate, event loop, and module cache. postMessage copies unless you transfer, and Atomics.wait on the main thread blocks the whole server.

Node.jsWorker ThreadsConcurrencyPerformance
3D illustration of a parent process cube spawning child cubes with message envelopes on a channel
Node.js

Node.js child_process: spawn, exec, fork, and IPC Channels

spawn streams and never uses a shell; exec buffers through /bin/sh and is the injection surface. fork adds an IPC channel, and killing a tree needs a process group.

Node.jsChild ProcessProcessIPC
3D illustration of a byte grid slab with encoding tiles flipping between hex and base64
Node.js

Node.js Buffer and TypedArray: Encodings and Binary Manipulation

A Buffer is a view over an ArrayBuffer, so byteLength is not string length and toString can silently corrupt split UTF-8. allocUnsafe and pooled buffers carry old data.

Node.jsBufferBinaryEncoding
3D illustration of a pipeline with source tank, transform chamber and destination tank with pressure gauges
Node.js

Node.js Streams: Readable, Writable, Transform, and pipeline

pipe() forwards data but not errors; pipeline() destroys the chain and rejects. Backpressure is the false return from write(), and _flush that never calls back hangs forever.

Node.jsStreamsBackpressurePerformance
3D illustration of file folder slabs with read and write arrows, a temporary swap tile and a watch eye
Node.js

Node.js fs/promises: Read, Write, Watch, and Atomic File Operations

writeFile truncates before writing, so a crash leaves half a file. The atomic pattern is temp file, fsync, rename; readFile loads everything, so large files need streams.

Node.jsfsFilesystemAsync
3D illustration of two gates labelled with import and require lanes beside a package json panel
Node.js

Node.js ESM vs CommonJS: import, require, and package.json exports

"type" decides how a .js file loads, and the exports field decides what a package exposes. Missing extensions, __dirname, and dual-package state are the usual failures.

Node.jsESMCommonJSModules
3D illustration of a circular conveyor with six phase stations and a priority chip jumping the queue
Node.js

Node.js Event Loop: Phases, Microtasks, and nextTick Order

Six phases, two queues that are not phases, and one rule: nextTick then microtasks drain between every callback. Why setTimeout and setImmediate swap order at top level.

Node.jsEvent LoopAsyncPerformance