Node.js is single-threaded in the sense that JavaScript execution runs on a single thread (the event loop). However, it is designed for non-blocking operations, meaning that time-consuming tasks like database queries, file I/O, and network requests do not block the main thread. Instead, Node.js delegates these tasks:
- Network calls (DB queries, API requests) → Handled by the OS or external servers asynchronously.
- CPU-intensive tasks (crypto, file operations) → Offloaded to the libuv thread pool, which consists of a fixed number of worker threads (not one per task).
- The event loop efficiently listens for task completion and schedules callbacks on the main thread, allowing high concurrency.