1

I'm new to nodejs, and I became curious about how nodejs handles asynchronous tasks in nodejs.

After reading documents from nodejs docs, I found that nodejs chose event loop / non-blocking operation model.

The event loop is what allows Node.js to perform non-blocking I/O operations — despite the fact that JavaScript is single-threaded — by offloading operations to the system kernel whenever possible.

What I understood is that nodejs event loop offloads non-blocking operations to the system kernel (and libuv thread pool I think?) to perform tasks asynchronously.

So my question is, what is the "core" difference between this model and multi-threaded operations model? It just looks like multi-threaded operations using system kernel handled by main thread. Is it just the benefit of not wasting resources doing context-switching or something? Is it ok to understand like "yeah, nodejs is single-threaded but it's almost the same with multi-threaded system"?

I read some documents but I couldn't figure out the answer for my question.

Sanushi Salgado
  • 1,195
  • 1
  • 11
  • 18
  • Related: https://stackoverflow.com/questions/21485920/single-threaded-event-loop-vs-multi-threaded-non-blocking-worker-in-node-js – jarmod Apr 06 '23 at 15:18
  • This should help https://www.youtube.com/watch?v=8aGhZQkoFbQ – Neeraj Apr 06 '23 at 15:52

0 Answers0