Node.js is single-threaded.
So why doesn’t your server freeze with 10,000 requests?
This confused me for months — until I understood the event loop.
Here’s the mental model that made it click
The 4 pieces you need to understand
1. JS Engine (e.g. V8)
Executes your JavaScript by parsing → compiling → running it, while managing memory (heap) and execution flow (call stack)
2. Call Stack
A single-threaded execution stack where synchronous code runs one function at a time — if it’s occupied by heavy work, nothing else (including callbacks) can run
3. Web APIs / Node APIs (libuv)
Background system that takes over async operations (timers, file system, network, DB), so the JS engine doesn’t block while waiting
4. Queues
Hold ready callbacks — microtasks (Promises) are processed immediately after current execution, while task queue (timers/I/O) runs only when the stack is free
🔁 The rule everything follows
1. Run all synchronous code (call stack)
2. Execute ALL microtasks (Promises)
3. Execute ONE task (timers, I/O)
4. Repeat
🍽️ Mental model
Node is a single chef
Takes orders (requests)
Hands off long work (async APIs)
Keeps working instead of waiting
Comes back when tasks are ready
⚠️ If the chef is stuck → everything stops
#nodejs #javascript #nestjs #backend #softwareengineering
Cool Avinash, excited if you add more DB support, ORM support and Framework support, from cli i can pass what db,orm,framework i need