What Node.js is and how it runs

Beginner · 8 min

Node is V8 plus libuv plus C++ bindings around one JavaScript thread. What it adds over the browser, and why that design handles many connections.

ByteMonk · 8 min

What Node.js is and how it runs

The player loads from youtube-nocookie.com when you press play. Nothing reaches YouTube before that.

Taught by ByteMonkReport a problem with this video
Not started
Set this lesson's status

What you'll learn

  • Node.js is not a language or a framework. It is a program that embeds the V8 JavaScript engine, adds the libuv event loop and thread pool, and exposes operating-system features to JavaScript through C++ bindings.
  • Your JavaScript runs on a single thread. Waiting for files, sockets and timers is handed to the operating system or to libuv's pool, so that one thread is free to run other callbacks in the meantime.
  • Node has no `window`, no `document` and no rendering. In exchange it has `process`, `node:fs`, `node:http`, `node:crypto` and the rest of the standard library, plus web-standard globals such as `fetch`, `URL` and `AbortController`.
  • This design is excellent for work that mostly waits (HTTP servers, proxies, tools that talk to databases and APIs) and poor for long computations on the main thread, which stall every other request.
  • `process.versions` tells you exactly which V8, libuv, OpenSSL and Node-API versions your binary contains.

The problem Node was built to solve

In 2009 a typical web server gave each connection its own thread or process. A thread that is waiting for a database reply sits idle but still costs memory, and ten thousand of them will exhaust a machine. Ryan Dahl’s observation was that most of a web server’s life is spent waiting: for the network, for the disk, for another service. Waiting does not need a thread. It needs someone to say “tell me when it’s done.”

JavaScript already had that shape. In a browser you write button.addEventListener('click', handler) and hand control back. If you took the same language, removed the page, and wired it to the operating system’s “tell me when it’s done” facilities, you would have a server runtime. That is Node.

Three parts in one binary

When you run node app.js, three components cooperate:

  • V8 is Google’s JavaScript engine, the same one inside Chrome. It parses your code, compiles it, and runs it. It knows nothing about files or sockets.
  • libuv is a C library that provides the event loop, a pool of worker threads, and portable access to the operating system’s async I/O (epoll on Linux, kqueue on macOS, IOCP on Windows).
  • Bindings and the standard library are C++ code plus a lot of JavaScript. They connect V8 to libuv so that fs.readFile, net.createServer and crypto.pbkdf2 exist as JavaScript functions.

You can see the exact versions inside the binary you are running:

console.log(process.versions.node, process.versions.v8, process.versions.uv);

On the Node 26.13.1 used to check this lesson that prints Node 26.13.1, V8 14.6 and libuv 1.53. Upgrading Node upgrades all three together.

One thread of JavaScript, many things in flight

Run this as an ES module:

import { readFile } from 'node:fs';

readFile(import.meta.filename, (err, data) => console.log('file read:', data.length > 0));
console.log('read requested');

The output is read requested first, then file read: true. readFile made a request and returned immediately. libuv did the actual reading, and when it finished, it queued your callback. The thread never sat and waited.

Think of a restaurant with one waiter. He takes your order, hands it to the kitchen, and goes to the next table. He does not stand at the pass staring at your pasta. The kitchen (the OS and the thread pool) works in parallel; the waiter (your JavaScript) is a single person who never idles as long as there is another table to serve. The same picture explains the failure case: if the waiter decides to personally cook a ten-minute dish, every table waits.

That is the one rule to carry forward. JavaScript callbacks must be short. Heavy computation belongs in a worker thread, covered in worker threads. The mechanics of the queue are the subject of the event loop phases, and blocking vs non-blocking I/O shows how to spot the stalls.

What Node adds, and what it leaves out

Node is JavaScript with the page removed and the machine added. Compare the globals:

console.log(typeof window, typeof document, typeof fetch, typeof process);
// undefined undefined function object

There is no window or document, because there is nothing to render. There is a process object (covered in the process object), the node:fs, node:net, node:http, node:child_process and node:crypto modules, and the ability to bind a port and accept connections. Node also ships web-standard APIs where they make sense on a server: fetch, URL, AbortController, TextEncoder, structuredClone, crypto.subtle and web streams. Code that sticks to those runs in both places.

The language is the same one you learned in the JavaScript roadmap. Node does not change what a closure or a promise is. It changes what the surrounding environment offers.

Where Node fits and where it does not

Node suits programs that spend their time waiting on I/O: web APIs, gateways, real-time servers, build tools, scripts that call other services. It is a poor fit for programs that spend their time computing on the main thread, such as video encoding or large matrix maths, unless that work is moved to workers or native code. For a broader comparison of runtime and language choices see choosing a backend language and runtime.

What the video covers

ByteMonk’s video is about the single-thread model: how one thread can serve thousands of requests by relying on non-blocking I/O and the event loop. No transcript was available, so the claim here is limited to that scope. Its title and description do not mention process.versions, the web-standard globals or the bindings layer, so treat those as carried by the prose above. The shorter Codevolution videos under “go deeper” cover V8 on its own and a plain introduction to Node, both recorded in 2022 against Node 18. The architecture they describe still holds on current versions.

Where this fits

This is the starting point for the roadmap. Next comes the runtime landscape, then installing and managing versions.

Check yourself

  1. 01If JavaScript is single-threaded, how can a Node server handle thousands of open connections?

    It does not wait on them. A socket read or a file read is started, the operating system or libuv does the waiting, and the JavaScript thread moves on. When the result is ready, a callback is queued and the thread runs it. One thread only ever does the short bursts of JavaScript work, not the waiting.

  2. 02Which part of Node is responsible for the event loop and the thread pool, and which part runs your code?

    libuv owns the event loop and the thread pool. V8 compiles and runs your JavaScript. The C++ bindings are the glue that lets a call like `fs.readFile` cross from JavaScript into libuv and back.

  3. 03Which two things does a browser have that Node lacks, and which two things does Node have that a browser lacks?

    A browser has the DOM (`document`, `window`) and rendering APIs such as `localStorage` and `alert`. Node has direct file-system and process access (`node:fs`, `process`) and the ability to open raw TCP or HTTP servers (`node:net`, `node:http`).

  4. 04Why is `while (Date.now() < end) {}` inside a request handler so damaging in Node?

    It keeps the only JavaScript thread busy. No other callback can run until it finishes, so every other request waits, even requests that would have been instant.

Go deeper

Notes

Private to you

Esc
↑↓ navigate↵ open? shortcuts

Keyboard shortcuts

Press Esc to close

Anywhere

⌘K
Search and commands
/
Search
?
This sheet
Esc
Close

Reading a lesson

J
Next lesson
K
Previous lesson
B
Bookmark