Back to Groups
Development

JavaScript: Node service engineer

Node.js 22, ESM. Bound asynchronous work, share in-flight requests, and control retries at service boundaries. Review names and integration points before use.

javascriptworkflowsnodejscodejavascript-developer
NI
Nina
0likes12snippets

Try it here

Loading snippet…

Your typing stays in this tab. Nothing is saved or sent.
Snippets (12)
;js-map-bounded
Map with a bounded number of async workers
async function mapLimit(items, limit, mapper) { if (!Number.isInteger(limit) || limit < 1 || limit
;js-query-url
Set encoded query parameters without string concatenation
function withQuery(base, values) { const url = new URL(base); for (const [key, value] of Object.
;js-fetch-json
Fetch a bounded JSON response with a deadline
async function fetchJson(url) { const target = new URL(url); if (target.protocol !== "https:" ||
;js-debounce
Cancelable trailing debounce for a synchronous callback
function debounce(callback, delayMs = 250) { if (!Number.isInteger(delayMs) || delayMs < 0 || dela
;js-event-deadline
Wait for an EventEmitter event with a deadline
import { once } from "node:events"; async function waitForEvent(emitter, eventName, timeoutMs = 500
;js-natural-sort
Sort a copy by a natural-text label
function sortByLabel(items, labelOf, locale = "en") { const collator = new Intl.Collator(locale, {
;js-literal-regex
Match literal text inside a regular expression
function literalPattern(text) { if (typeof text !== "string" || text.length > 1000) { throw ne
;js-object-diff
Compare selected own properties
function changedFields(before, after, fields) { return fields.filter((key) => { const had = Ob
;js-single-flight
Share one pending read per cache key
function createSingleFlight(maxPending = 100) { if (!Number.isSafeInteger(maxPending) || maxPendin
;js-retry-read
Retry a classified read with cancellation
import { setTimeout as delay } from "node:timers/promises"; async function retryRead(operation, sho
;js-request-id
Sanitize an incoming request ID for logs
import { randomUUID } from "node:crypto"; function requestId(header) { if (typeof header === "str
;js-ttl-cache
Cache bounded lookup results with expiration
function createTtlCache(maxEntries = 100, ttlMs = 30_000) { if (!Number.isSafeInteger(maxEntries)