What is libuv in Node.js?
Answer
libuv is the C library that powers Node.js's event loop and asynchronous I/O. It provides the abstraction layer between Node.js and the operating system. Key responsibilities: (1) Event loop implementation — the multi-phase loop (timers, poll, check, etc.); (2) Thread pool — a pool of threads (default 4, configurable via UV_THREADPOOL_SIZE) for operations that cannot be done asynchronously by the OS, such as file system operations, DNS lookups, and cryptography. While the event loop itself is single-threaded, these operations are offloaded to libuv's thread pool. When completed, the result callback is queued to the event loop; (3) Cross-platform I/O — abstracts OS differences (epoll on Linux, kqueue on macOS, IOCP on Windows) for consistent async I/O; (4) Timer management, signal handling, and child process utilities. Increasing UV_THREADPOOL_SIZE can improve performance for apps with heavy file system or cryptography workloads.
Previous
What are Worker Threads in Node.js?
Next
What is the difference between cluster and Worker Threads?