TechEarl
Topic · JavaScript

JavaScript

Frontend and Node patterns that survive contact with real users, real bugs, and real deadlines.

39 articlesWritten by Ishan Karunaratne
JavaScript and Node.js patterns for frontend and backend that hold up in production.
More in JavaScript
Use the Web Crypto API in Node.js through globalThis.crypto: randomUUID, getRandomValues, and crypto.subtle, available globally in Node 19+ with no shim.

Using Web Crypto (globalThis.crypto) in Node.js

globalThis.crypto (the Web Crypto API) is a global in Node 19+ with no shim or flag: crypto.randomUUID(), getRandomValues(), and crypto.subtle. How it differs from the node:crypto module, and when you still need a shim.

Stream a fetch() response in JavaScript: async-iterate response.body, decode with TextDecoderStream, and parse NDJSON line by line with no dependencies.

Stream a fetch() Response in JavaScript (NDJSON, line-by-line)

Read a fetch() response as it arrives instead of buffering the whole body. Async-iterate response.body, decode with TextDecoderStream, and split NDJSON line by line with a dependency-free TransformStream. The same pattern that consumes SSE and streaming LLM token responses.

How to register a custom Gutenberg block with block.json: the metadata-first approach using register_block_type() on the init hook, the file: asset convention, and a @wordpress/scripts build step that ships edit.js and save.js.

Register a Custom Gutenberg Block with block.json

The modern way to register a custom Gutenberg block: a block.json metadata file, register_block_type( __DIR__ . '/build/callout' ) on the init hook, and a @wordpress/scripts build step. One source of truth for PHP and JS.

nvm vs fnm vs Volta comparison: which Node.js version manager to choose by speed, auto-switching, and per-project pinning

nvm vs fnm vs Volta: Which Node Version Manager?

nvm vs fnm vs Volta, compared by speed, auto-switching, platform support, and pinning model. Which Node version manager to pick in 2026, with install commands, the .nvmrc vs package.json question, and honest caveats from running all three.

How async functions work in JavaScript: they desugar to a generator plus a runner. Plus async generators with for await...of, the AsyncFunction constructor, and why you should not detect async-ness.

How async Functions Really Work in JavaScript

What an async function actually is under the hood: it desugars to a generator plus a built-in runner. Plus async generators with for await...of, the AsyncFunction constructor, and why detecting async-ness is a trap.

How to fix the NODE_MODULE_VERSION mismatch error in Node.js by rebuilding native modules against the current ABI

Fix NODE_MODULE_VERSION Mismatch in Node.js

The NODE_MODULE_VERSION mismatch error means a native addon was compiled against a different Node ABI than the one now running it. Here is what the numbers mean, the one-line fix, and the Electron, Docker, and CI variants that catch people out.

JavaScript has no blocking sleep. Await a Promise around setTimeout, use Node's native timers/promises, poll for a condition with AbortSignal, and know the setTimeout 4ms clamp and Date.now vs performance.now difference.

How to sleep(), wait, and poll in JavaScript

JavaScript has no blocking sleep(). Here is the one-liner that actually works (await a Promise around setTimeout), Node's native timers/promises, a cancellable polling helper, and the setTimeout 4ms-clamp and Date.now vs performance.now gotchas.

How to uninstall Node.js completely on Linux, macOS, and Windows, including removing leftover npm, npx, and global package directories

How to Uninstall Node.js (Every Install Method)

How to uninstall Node.js cleanly on Linux, macOS, and Windows: version managers (nvm, fnm, Volta, n), the official installer, apt/dnf/brew/winget/choco, Docker, plus the leftover npm/cache/PATH files everyone forgets to delete.

A complete guide to JavaScript promises: states, then/catch/finally, async/await, and the await-in-a-loop trap, with runnable examples.

JavaScript Promises Explained: A Complete Guide

How JavaScript promises actually work: the three states, .then/.catch/.finally, async/await as the default modern style, and the gotchas that bite (the explicit-construction antipattern and the await-in-a-loop serialization trap).

A practical guide to the JavaScript fetch() API: the request/response model, checking response.ok because fetch does not reject on 4xx/5xx, parsing JSON, headers, methods, bodies, and credentials, in the browser and in Node 18+.

The fetch() API: A Practical Guide

A practical guide to the fetch() API: the request/response model, why response.json() returns a promise, and the one surprise that bites everyone, fetch does not reject on 404 or 500. Plus headers, methods, bodies, credentials, and why fetch is now global in Node 18+.

Merge two arrays in JavaScript: copy-merge with spread, merge in place with push, or copy with concat, and the choice by mutation, memory, and large-array safety.

How to Merge Two Arrays in JavaScript

Merge two arrays in JavaScript three ways: copy-merge with spread [...a, ...b], merge in place with a.push(...b), or copy with a.concat(b). Which to pick by mutation, memory, and the spread arg-count limit that bites on very large arrays.

Terminal output of node --version and npm --version showing the installed Node.js and npm release numbers on the command line

How to Check Your Node.js and npm Version

Run node --version and npm --version to see what you have installed. This covers every way to check Node and npm, finding which install is on PATH, reading the version inside a script, and the gotchas with version managers and multiple installs.