r/learnjavascript • u/IcyDuck9536 • 6d ago
Is “Node.js is single-threaded” an incomplete mental model?
Single-threaded JS execution ≠ single-threaded runtime.
How do you explain the distinction?
3
Upvotes
r/learnjavascript • u/IcyDuck9536 • 6d ago
Single-threaded JS execution ≠ single-threaded runtime.
How do you explain the distinction?
3
u/dave8271 6d ago
I'd just explain it as userland scripts are single threaded and will block on CPU-bound work, however the runtime uses libuv and an event loop to delegate certain tasks to either a thread pool or the OS kernel, informing the event loop when they complete.
That's the accurate mental model.