What is the difference between JavaScript event loop and Node.js event loop?

In JavaScript, the event loop is used in the engine. Here is one diagram illustrating this from this article .


(source: mybalsamiq.com )

For Node.js, an event loop is also implemented here. Quoting from this question .

The Node.js event loop runs on a single thread, which means that the application code you write is evaluated on a single thread. Nodejs itself uses a lot of threads via libuv, but you never have to deal with them when writing nodejs code.

However, this is still abstract to me in the node.js event loop.

  • Is there any image to present it more clearly?
  • What is the difference between these two event loops?
+4


source to share


3 answers


What's the difference between these two event loops?

Nothing. Nodejs is a JavaScript 1 engine .

1: Or rather one of them, there are other engines implementing the same language and the same concept of the event loop.



Is there an image to present it more clearly?

There's a lot. But I think animation is better :-) This jsconf talk from Philip Roberts is praised all over the place.

+1


source


The Nodejs event loop is implemented differently than the browser based event loop.

This is a point of great confusion in the Nodejs community.

Although Nodejs uses Google V8 at runtime, it hasn't used V8 to implement the event loop.

Nodejs uses the Libuv library (written in C ++) to implement the event loop.



The above diagram that works for the JS event loop is different from the Nodejs event loop.

There are three links you should study to fully understand the Nodejs event loop:

  1. https://nodejs.org/en/docs/guides/event-loop-timers-and-nexttick/
  2. http://docs.libuv.org/en/v1.x/design.html
  3. https://www.youtube.com/watch?v=sGTRmPiXD4Y
+2


source


I found one image describing the event loop in Node.js by @ BusyRich

0


source







All Articles