Beginner Node.js Interview QuestionsBeginnerConcept
Node.js · Question 13
What is the Node.js architecture?
Direct answer
Node layers JavaScript user code on Node bindings (C++), libuv for the event loop and async I/O, and V8 for execution — with optional worker threads and child processes for parallelism outside the main loop.
A complete mental model stacks four pieces: your JS → Node core modules (written in JS + C++) → libuv → operating system kernel.
- Application layer — Express/Fastify routes, your business logic, npm packages.
- Node API surface — fs, http, crypto, stream wrappers exposing libuv to JavaScript.
- libuv — event loop, thread pool, cross-platform polling (Q8–9).
- V8 — executes JS and calls into bindings when you invoke node:fs.readFile.
architecture-flow.js
import http from "node:http";
import fs from "node:fs";
// JS handler
const server = http.createServer((req, res) => {
// Binding → libuv async read → callback when ready
fs.readFile("./data.json", (err, buf) => {
res.writeHead(200, { "Content-Type": "application/json" });
res.end(buf);
});
});
server.listen(4000);