libuv
The C library inside Node.js that runs the event loop, performs asynchronous I/O and manages the thread pool.
In more detail
libuv hides the differences between operating systems: it uses epoll on Linux, kqueue on macOS and I/O completion ports on Windows to learn when sockets are ready. Work the kernel cannot do asynchronously, such as most file operations, some DNS lookups and some crypto, runs on its thread pool instead. Its function names start with uv_, such as uv_run.
Related terms
- event loop — The central loop of an asynchronous program that waits for events, such as timers firing or data arriving, and runs the matching callbacks.
- thread pool — A fixed or bounded set of reusable worker threads that take tasks from a queue, instead of creating a new thread for each task.
- event demultiplexer — The part of libuv that waits on many sockets and files at once and reports which of them are ready, using facilities such as epoll.
- epoll — The Linux kernel facility that lets one thread watch many file descriptors and be told which are ready for reading or writing.
Taught in
- V8 Engine & JIT Pipeline: Bytecode & Turbofan — Node.js Internals & Backend Services
- libuv Architecture: Event Demultiplexer & Thread Pool — Node.js Internals & Backend Services
- Event Loop Lifecycle: The Six Phases & libuv uv_run — Node.js Internals & Backend Services
- Timers Phase: setTimeout, Min-Heap Scheduling & Drift — Node.js Internals & Backend Services
- Poll & Check Phases: I/O Callbacks & setImmediate — Node.js Internals & Backend Services
- Close Phase & Signal Dispatch: Sockets & Teardown — Node.js Internals & Backend Services
- Asynchronous File I/O: node:fs/promises & Handles — Node.js Internals & Backend Services
- Directory Traversal: Recursive Readdir & fs.watch — Node.js Internals & Backend Services