Why is LIBUV needed in Node JS?

Ankur Verma picture Ankur Verma · May 19, 2019 · Viewed 7.2k times · Source

So, may be this question is too noob and novice to be asked but I still have no clue why LIBUV got a place in Node JS Architecture? So here is my understanding of NodeJs architecture.

  1. Node Js is built over V8
  2. V8 is a capable of running code written with EcmaScript standards.
  3. V8 is written in C++.
  4. So if you want to give any new functionality we can embed V8 in our C++ project and attach new code with new Embedded V8 in C++.

Now here is the doubt,

  1. Since V8 supports EcmaScript Javascript that means it has the capability to run callbacks written with the standards of EcmaScript.
  2. So we can add code for File System Access, Http server & DB access in C++ since there are libraries (header files) that gives that functionality since Java is written in C++ (correct me if I am wrong) and Java has the capability to do the same.
  3. Now if we can add these functionality in C++ where does the place for Libuv come in to the picture of NodeJs architecture.

Thanks in advance and Happy Coding :)

Answer

Shobhit Chittora picture Shobhit Chittora · May 19, 2019

Check the docs below -

https://nodejs.org/en/docs/meta/topics/dependencies/#libuv

Another important dependency is libuv, a C library that is used to abstract non-blocking I/O operations to a consistent interface across all supported platforms. It provides mechanisms to handle file system, DNS, network, child processes, pipes, signal handling, polling and streaming. It also includes a thread pool for offloading work for some things that can't be done asynchronously at the operating system level.

So to sum it up, V8 provides the functionalities related to running JS files, but to use system resources like Network, Files, etc., libuv is used. Also it provides a threading model for accessing the resources mentioned.