How one Node.js thread handles thousands of requests.
The event loop, built up one diagram at a time, plus the one thing that blocks it.
Welcome to the first Happy Path newsletter issue.
Node.js executes JavaScript on a single thread. A single Node server still handles thousands of requests at the same time. How is this possible? The event loop.
The short version fits in one picture:

The rest of this email builds that picture one step at a time.
Step 1: what a server does
A web server is a program that waits for requests and sends back responses. With Node, the server is JavaScript code (often an Express app), and Node is the runtime that executes it. Most of a request's time is spent waiting: on a database, a file, another API.

Step 2: one worker
Node executes JavaScript on a single thread, one line at a time.

Step 3: a slow task arrives
A database query or a file read. Node hands it off instead of waiting for it.

Step 4: meanwhile
The next request is executed, so the thread doesn't sit idle.

Step 5: the task finishes
Its callback joins a queue.

Step 6: the event loop
When the thread is free, it picks the next callback from the queue. That’s the event loop.

The catch
One long synchronous task keeps the thread busy, and the queue just waits.

That’s it
Thanks for reading the first issue of The Happy Path. Which topic should the next one explain? Let me know by replying to this email.