AceDevHub
Beginner Node.js Interview QuestionsBeginnerConcept

Node.js · Question 8

What is libuv in Node.js?

Direct answer

libuv is the C library Node uses for the event loop, async I/O, thread pool, timers, and cross-platform abstractions over epoll/kqueue/IOCP — V8 runs JavaScript; libuv handles waiting on disk and network.

Node is not built directly on OS APIs in JavaScript — libuv provides a unified layer so the same Node code runs on Linux, macOS, and Windows with consistent async behavior.

  • Event loop — phase scheduling (timers, poll, check) lives in libuv.
  • Thread pool — worker threads for operations that cannot be fully async at OS level (Q9).
  • Network & fs — TCP, UDP, pipes, async file operations bridge through libuv.
  • Cross-platform — epoll (Linux), kqueue (macOS), IOCP (Windows) hidden behind one API.
libuv-io.js
import dns from "node:dns";
import fs from "node:fs";

// Network I/O — often true async via OS (no thread pool)
fs.readFile("package.json", () => console.log("fs done"));

dns.lookup("nodejs.org", () => console.log("dns done"));

console.log("JS continues — libuv handles waits");