tezvyn:

Node.js & Express

Node.js, Express, Fastify, NestJS, Bun, Deno

276 bites

More in Node.js & Express — page 6

Node.js & Express71 sec read

Query params vs route params in Express

WHAT IT TESTS: distinguishing two ways to pass data in a URL. OUTLINE: query string values via req.query.q, named path segments via req.params.id, query is optional, route params are part of the matched pattern. RED FLAG: mixing up req.query and req.params.

Node.js & Express67 sec read

Serving static files in Express

WHAT IT TESTS: knowing the built-in static middleware. OUTLINE: app.use with express.static pointing at the public directory, files served relative to that root, often combined with an absolute path.

Node.js & Express75 sec read

Minimal Express Hello World server

WHAT IT TESTS: basic Express setup fluency. OUTLINE: import express, create an app, define app.get on the root sending a response, call app.listen on a port. RED FLAG: forgetting app.listen or confusing the require with the app instance.

Node.js & Express82 sec read

http.Agent and connection pooling

WHAT IT TESTS: reusing TCP connections for outbound requests. OUTLINE: the agent pools and keeps sockets alive, avoiding repeated TCP and TLS handshakes, controlled by keepAlive and maxSockets. RED FLAG: thinking each request always needs a fresh connection.

Node.js & Express85 sec read

Backpressure in Node.js streams

WHAT IT TESTS: flow control between fast producer and slow consumer. OUTLINE: backpressure pauses the readable when the writable buffer fills, pipe and pipeline manage it automatically, pipeline also propagates errors and cleans up.

Node.js & Express82 sec read

Scaling across cores with cluster and os

WHAT IT TESTS: scaling single-threaded Node across cores. OUTLINE: os.cpus gives core count, the primary forks one worker per core, all workers share the listening port, the OS load-balances connections. RED FLAG: thinking one Node process uses all cores.

Node.js & Express77 sec read

fs.watch vs fs.watchFile

WHAT IT TESTS: file change detection mechanisms. OUTLINE: watch uses OS event notifications, efficient but inconsistent across platforms, watchFile polls stat at an interval, reliable but slower. RED FLAG: not knowing watch is event based versus polling.

Node.js & Express69 sec read

path.resolve vs path.join

WHAT IT TESTS: nuance of path construction. OUTLINE: join concatenates and normalizes relative segments, resolve builds an absolute path right to left from cwd and resets on any absolute segment. RED FLAG: treating them as interchangeable.

Node.js & Express81 sec read

Reading a POST body from the request stream

WHAT IT TESTS: that req is a readable stream. OUTLINE: body arrives in chunks via data events, accumulate them, on the end event concatenate and JSON.parse inside try/catch. RED FLAG: expecting req.body to exist or parsing before all chunks arrive.

Node.js & Express80 sec read

Counting lines in a 5GB log file efficiently

WHAT IT TESTS: streaming versus buffering large data. OUTLINE: readFile loads all 5GB into RAM and may exceed buffer limits, instead stream with createReadStream plus readline and count line by line. RED FLAG: proposing readFile then split on newlines.

Node.js & Express73 sec read

Minimal HTTP server with the http module

WHAT IT TESTS: knowing the raw http API beneath frameworks. OUTLINE: createServer with a request listener, set status and Content-Type, end the response, call listen on 3000. RED FLAG: forgetting res.end so the connection hangs.

Node.js & Express68 sec read

Why use path.join over string concatenation

WHAT IT TESTS: awareness of cross-platform path handling. OUTLINE: path.join uses the correct OS separator, collapses duplicate slashes, normalizes . and .. segments. RED FLAG: hardcoding forward slashes and assuming concatenation always works.

Node.js & Express79 sec read

fs.readFileSync vs fs.readFile

WHAT IT TESTS: grasp of blocking vs non-blocking I/O. OUTLINE: sync blocks the event loop and returns directly, async takes a callback or promise, only sync is safe at startup. RED FLAG: using readFileSync inside a request handler.

Node.js & Express88 sec read

Async iterators and for await...of for streaming

WHAT IT TESTS: streaming vs buffering everything. OUTLINE: async iterators yield values lazily over time; for await...of consumes them sequentially with backpressure, keeping memory bounded.

Node.js & Express84 sec read

Promise.all vs Promise.allSettled

WHAT IT TESTS: choosing fail-fast vs collect-all. OUTLINE: all rejects on the first failure; allSettled always fulfills with a status/value or reason per input. Use allSettled when partial success is acceptable.

Node.js & Express2 min read

Bounded concurrency for many async requests

WHAT IT TESTS: limiting concurrency, not just running parallel. OUTLINE: chunk the array and await Promise.all per chunk, or run a fixed worker pool pulling from a shared index; cap in-flight requests. RED FLAG: firing all 1000 at once or going fully serial.

Node.js & Express85 sec read

Comparing the three async error-handling styles

WHAT IT TESTS: fluency across async error styles. OUTLINE: callbacks pass err as first arg; Promises route errors to catch; async/await uses try/catch; an unhandled rejection can crash the Node process.

Node.js & Express85 sec read

Handling async errors in Express middleware

WHAT IT TESTS: routing async errors into Express. OUTLINE: await inside try/catch and call next(err) on failure, or wrap the handler in an async error adapter; never let a rejected Promise go uncaught.

Node.js & Express84 sec read

Running independent requests with Promise.all and race

WHAT IT TESTS: concurrent Promise combinators. OUTLINE: start all requests then await Promise.all to get all results or fail fast on first rejection; use Promise.race when only the fastest settled result matters.

Node.js & Express80 sec read

Output order of sync, microtask, and macrotask

WHAT IT TESTS: microtask vs macrotask priority. OUTLINE: C runs first synchronously, then B drains from the microtask queue, then A from the macrotask queue. RED FLAG: claiming setTimeout(0) beats the Promise, or that order is random.