What is libuv in a Node.js interview?
A C library that provides cross-platform async I/O for Node.js. It handles the event loop, file system and network operations, the thread pool for blocking work, and timers. Without libuv, Node.js would not be non-blocking.
Verify This Answer
Cross-check this information using these trusted sources:
More FAQs in libuv and Async I/O Interview Questions for Node.js
Blocking code stops the main thread until it completes. Non-blocking code returns immediately and processes the result via a callback when complete. Node.js is single-threaded, so blocking code stops all requests, which is the biggest performance concern.
libuv has a thread pool (default 4 threads) for operations that cannot be done asynchronously, like certain file system, DNS, and crypto operations. These run off the main thread. Callbacks run on the main thread via the event loop.
Timers (setTimeout), pending callbacks, idle/prepare (internal), poll (I/O callbacks), check (setImmediate), and close callbacks. Each phase runs specific callbacks in order, which explains the order async code runs.
Still have questions?
Browse all our FAQs or reach out to our support team
