Roadmap › 4. Frontend › Step 45
Node

Node.js — Runtime Internals, Express, APIs and SQL Server

What Node.js is and how it works inside (V8, libuv, the event loop phases, thread pool, non-blocking I/O), modules (CommonJS vs ES modules), npm and package.json, the core modules (fs, path, http, events, streams, buffer), asynchronous patterns (callbacks, promises, async/await), Express.js REST APIs with middleware and error handling, project folder structure, connecting to SQL Server (mssql, Prisma, Sequelize), authentication with JWT, worker threads and clustering, testing, security, performance, deployment and the Node.js interview questions.
What it is & where it is used

Node.js is a JavaScript runtime that runs JavaScript outside the browser — on servers, build tools and CLIs. It uses Google's V8 engine to execute JavaScript and libuv to provide non-blocking I/O through an event loop, so one process can handle thousands of concurrent connections with a single main thread.

Used forExamples
Web APIs and backendsExpress, Fastify, NestJS, Koa
Full stack frameworksNext.js, Nuxt, Remix, SvelteKit
Real-time appsChat, live dashboards with Socket.IO/WebSockets
Toolingnpm, Vite, webpack, Angular CLI, ESLint, TypeScript compiler
ServerlessAWS Lambda, Azure Functions, Vercel Functions

Node.js vs ASP.NET Core: both are fast, cross-platform backends. Node shares one language (JavaScript/TypeScript) with the frontend and has the largest package ecosystem (npm); .NET offers strong typing by default, multithreaded CPU performance and a richer built-in framework.

Versions & history
VersionYearHighlights
0.12009Ryan Dahl creates Node.js (V8 + event loop)
0.x / io.js2010–2015npm (2010), Express (2010); io.js fork merges back → Node.js Foundation (2015)
4–82015–2017ES2015+ support, LTS releases begin, async/await (v7.6/8)
10–122018–2019Worker threads, HTTP/2, N-API stable
14–162020–2021ES modules stable, optional chaining, Apple Silicon support
182022Global fetch, built-in test runner (node:test), watch mode later
202023Permission model (experimental), stable test runner, single executable apps
222024 (LTS)require() of ES modules, WebSocket client, --experimental-strip-types (run TypeScript)
242025 (LTS from Oct 2025)npm 11, V8 13.x, URLPattern global, TypeScript type stripping on by default
252025 (Current)Next "current" line; even versions become LTS each October

Release model: a new major every April and October; even-numbered releases become LTS (30 months of support). Use an Active/Maintenance LTS version in production.

Lifecycle

How Node.js handles a request:

  1. node server.js starts the process: V8 is initialised, your module is loaded and executed top to bottom (synchronous setup), then the event loop starts.
  2. http.createServer(...).listen(3000) registers a listening socket with the OS via libuv.
  3. A request arrives → the OS notifies libuv (epoll/kqueue/IOCP) → the event loop runs your request callback on the main thread.
  4. Your handler calls await db.query(...) → the query is sent on a socket (non-blocking) and the handler yields; the main thread serves other requests.
  5. When the DB answers, the promise resolves; its continuation is queued as a microtask and runs on the main thread.
  6. File-system operations, DNS lookups, crypto and zlib run on libuv's thread pool (4 threads by default) and report back to the loop.
  7. The response is written; when there is nothing left to do (no timers, sockets or pending work), the process exits.

Event loop phases (libuv):

text
   ┌───────────────────────────┐
┌─>│ timers                    │  setTimeout / setInterval callbacks whose time has come
│  ├───────────────────────────┤
│  │ pending callbacks         │  some deferred system callbacks (e.g. TCP errors)
│  ├───────────────────────────┤
│  │ idle, prepare             │  internal
│  ├───────────────────────────┤
│  │ poll                      │  retrieve new I/O events; run I/O callbacks; may block here waiting
│  ├───────────────────────────┤
│  │ check                     │  setImmediate callbacks
│  ├───────────────────────────┤
└──┤ close callbacks           │  socket.on('close') etc.
   └───────────────────────────┘
Between every callback: process.nextTick queue, then the Promise microtask queue are drained.
Tools used to develop
  • Runtime & package managers: Node.js (nvm / nvm-windows / fnm to switch versions), npm, pnpm, yarn; npx.
  • Frameworks: Express, Fastify, NestJS (Angular-like structure, DI), Koa, Hono.
  • Data: mssql (SQL Server via tedious), Prisma ORM, Sequelize, TypeORM, Knex, pg, mysql2, Mongoose.
  • Dev tools: nodemon / node --watch, ts-node / tsx, ESLint, Prettier, Chrome DevTools (node --inspect), VS Code debugger.
  • Testing: node:test, Jest, Vitest, Supertest (HTTP), Playwright.
  • Production: PM2, Docker, clinic.js (performance), OpenTelemetry, pino/winston (logging).