Node.js Architecture, V8 Engine & Single-Threaded Event Loop0%

Node.js Architecture, V8 Engine & Single-Threaded Event Loop

Beginner12 min read•Updated: Jul 11, 2026
Study MaterialsCheatsheet

Node.js Architecture, V8 Engine & Single-Threaded Event Loop

Node.js is an open-source, cross-platform JavaScript runtime environment built on Google Chrome's V8 JavaScript engine. Node.js executes JavaScript outside the browser, enabling developers to build scalable, high-performance network applications, microservices, and backend APIs using a single programming language across the entire stack.


1. What Makes Node.js Unique?

Traditional server environments (like Apache with PHP or Java servlets) historically spawned a new operating system thread for each incoming client request. A server handling 10,000 concurrent requests would require 10,000 threads, quickly exhausting server RAM and spending tremendous CPU cycles on thread context switching.

In contrast, Node.js operates on a single-threaded, non-blocking, event-driven architecture:

  1. 1
    Google V8 Engine: Written in C++, it parses and compiles modern JavaScript directly into machine code at runtime with Just-In-Time (JIT) compilation.
  2. 2
    Single-Threaded Execution: JavaScript application code runs on a single main thread, avoiding multithreaded race conditions and locking deadlocks.
  3. 3
    Libuv C Library: Handles all low-level asynchronous I/O operations (file system, network sockets, DNS, database pooling) using native OS kernel notifications (epoll on Linux, kqueue on macOS, IOCP on Windows) and an internal C thread pool.

2. The Architectural Diagram

Node.js Event Loop ArchitectureClick to Zoom
Node.js Event Loop Architecture

3. How the Event Loop Works

The Event Loop is the heart of Node.js. It continuously monitors the Call Stack and task queues, orchestrating when asynchronous callbacks are pushed to the stack for execution.

The Event Loop cycles through several distinct phases in each "tick":

PhaseResponsibilityExample Tasks
TimersExecutes callbacks scheduled by setTimeout() and setInterval()Delayed notifications, interval timers
Pending CallbacksExecutes I/O callbacks deferred to the next loop iterationSystem-level network socket error callbacks
Idle, PrepareUsed internally by Node.js for diagnostics and runtime housekeepingInternal Libuv operations
PollRetrieves new I/O events and executes their callbacksIncoming HTTP requests, file read buffers
CheckExecutes callbacks registered by setImmediate()Code explicitly deferred until after poll phase
Close CallbacksHandles resource cleanup and teardownsocket.on('close', ...)

4. Practical Code Example: Non-Blocking Execution

JavaScript
const fs = require('fs');
 
console.log('1. Start program execution');
 
// Asynchronous non-blocking file read handled by Libuv
fs.readFile(__filename, 'utf8', (err, data) => {
if (err) throw err;
console.log('3. Asynchronous file read callback completed (' + data.length + ' bytes)');
});
 
console.log('2. End program (Call stack clear)');

Output:

Output
1. Start program execution
2. End program (Call stack clear)
3. Asynchronous file read callback completed (1842 bytes)

The main thread never waits for disk or network I/O. It delegates the I/O to Libuv and immediately continues processing subsequent synchronous statements.


Interactive Quiz

Multiple Choice Questions

Question 1
Which core component of Node.js is responsible for compiling JavaScript code into native machine code?
Question 2
Why is Node.js considered non-blocking despite executing JavaScript on a single thread?
Question 3
In which phase of the Node.js Event Loop are callbacks registered via setImmediate() executed?
Question 4
What happens when CPU-intensive synchronous calculations (such as an infinite loop or heavy image compression) are run on the main Node.js thread?
Question 5
What is Libuv in the Node.js architecture?

Next Lesson

Call Stack, Callback Queue, Microtask Queue & Libuv Workers

Continue learning with hands-on practice, examples, and exercises in the upcoming topic.

Related Lessons

Practice Quiz

Test your understanding of this lesson with 5 questions. Each question has one correct answer.

PrevNext