How NodeJS works Asynchronously

We know that NodeJS is asynchronous. But the V8 engine upon which it is built is synchronous (meaning one process at a time). So, how come Node works?

There are basically three major components which Node deals with – V8 (engine), libuv (multi-platform C library ) and Operating System.

So when some event occurs or some request is made, libuv sends a request to OS and OS then puts that event in an event queue. Then V8 starts working on that code and after executing that code, it starts working on the next code present in the queue.

Thus even though V8 engine is synchronous in nature, the whole process works asynchronously because of the multiple file handling nature of the libuv and OS.

We know that NodeJS is asynchronous. But the V8 engine upon which it is built is synchronous (meaning one process at a time). So, how come Node works?

There are basically three major components which Node deals with – V8 (engine), libuv (multi-platform C library ) and Operating System.

So when some event occurs or some request is made, libuv sends a request to OS and OS then puts that event in an event queue. Then V8 starts working on that code and after executing that code, it starts working on the next code present in the queue.

Thus even though V8 engine is synchronous in nature, the whole process works asynchronously because of the multiple file handling nature of the libuv and OS.

Screenshot 2017-02-19 09.09.57.png

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s