Nodejs
179 bites tagged Nodejs — interview questions with model answers, and 60-second explainers.
CommonJS: Node.js's Original Module System
CommonJS treats each file as a private box of code. You share tools using `exports` and import them with `require`. It's the original module system for Node.js, used to organize code into reusable pieces.
Node.js Cluster: Scaling on a Single Machine
The `cluster` module turns a single-threaded Node.js app into a multi-process server that uses all CPU cores. It's ideal for scaling network applications on one machine by sharing a single port.
Libuv: The Engine Behind Node.js Async I/O
Libuv is the C library that powers Node.js's non-blocking I/O. It translates JavaScript's event loop into high-performance async calls for the host OS. The footgun is thinking this makes Node multi-threaded; it uses an event loop and a thread pool.
Node.js Child Processes: Escaping the Main Thread
A child process lets your Node.js app run external commands without blocking the event loop. Use it for CPU-intensive tasks like image processing or running system utilities. The footgun: using synchronous versions (`execSync`) will block your entire server.
Node.js Streams: Processing Data in Chunks, Not Blobs
Think of streams as a data conveyor belt, processing large files or network data in chunks instead of loading it all into memory. Use them for file I/O or network requests.
process.nextTick(): Cutting in Line on the Event Loop
process.nextTick() schedules a callback to run immediately after the current operation, before the event loop continues to timers or I/O. It's used for API consistency or error handling. The footgun is that overusing it can starve the event loop, blocking I/O.
Event Loop vs Crypto Module
Node's crypto module offers both synchronous and asynchronous versions of CPU heavy operations like password hashing; the sync versions block the single threaded event loop, while async versions offload the work to a background thread pool.
The Node.js Event Loop: Concurrency on a Single Thread
The Node.js event loop lets a single thread handle high concurrency by offloading I/O. It's ideal for web servers and APIs, but the footgun is that any long-running synchronous code will block the entire application, freezing all other requests.
Node.js Events and the EventEmitter
Node.js handles concurrency with an event-driven model, not threads. "Emitters" fire named events that "listeners" react to, enabling non-blocking I/O for things like file reads and web requests.
V8: The Engine Powering Chrome and Node.js
V8 is the engine that runs your JavaScript, translating it into machine code. It powers both the Chrome browser and the Node.js server-side runtime. The common footgun is confusing the engine (V8) with the runtime environment that provides it with APIs.
ESM vs. CJS: Navigating JavaScript's Module Divide
JavaScript has two module systems: modern, static ESM (`import`) and legacy, dynamic CJS (`require`). When publishing a library, you must support both. The footgun is shipping only ESM, as it breaks downstream projects that still use `require()`.
Get Nodejs bites daily.
Five a day, five minutes, offline. With quizzes so it sticks.
Open testing — you’ll join as an early tester.