What is Node.js and how does it work under the hood?

3 minbeginnernodejsv8libuvruntimearchitecture

Quick Answer

Node.js is a runtime that lets you run JavaScript outside the browser. It pairs Google's V8 engine (which compiles JS to machine code) with libuv (a C library providing the event loop and a thread pool for asynchronous I/O), plus a set of built-in modules and C++ bindings.

Detailed Answer

Answer: Node.js is a JavaScript runtime built on Chrome's V8 engine that lets you run JavaScript on the server, outside a browser.

The main pieces:

  1. V8 — Google's engine that parses and JIT-compiles JavaScript to native machine code. It provides the language itself (objects, functions, GC) but knows nothing about files, networks, or timers.
  2. libuv — a C library that provides the event loop, a thread pool, and cross-platform asynchronous I/O (file system, DNS, networking). This is what makes non-blocking I/O possible.
  3. Node bindings / C++ core — glue that exposes libuv and other native capabilities to JavaScript as built-in modules (fs, net, http, crypto, ...).
  4. Standard library — the JavaScript-level built-in modules you require/import.

How a request flows:

const fs = require('fs');

// JS asks Node to read a file and hands it a callback.
fs.readFile('data.txt', (err, data) => {
  console.log('done reading');
});
console.log('this logs first');
  • The readFile call is handed off to libuv, which performs the actual disk I/O on a background thread.
  • The main thread keeps running JavaScript (so 'this logs first' prints before 'done reading').
  • When the I/O finishes, libuv queues the callback, and the event loop runs it when the call stack is empty.

Interview tip: Be clear that V8 runs the JavaScript and libuv provides the asynchronous, event-driven I/O — Node is the combination, not just "JavaScript on the server."