Day 85 Node.js Libuv

For the past two blogs I’ve learned about event emitter in node.js which are custom JavaScript events that we create. However, today I learned about libuv a C++ core library used in Node. Libuv allows asynchronous inputs and outputs. This library listens and runs system events, which are things like finishing reading a file.

Libuv has a queue of events that have completed and this is happening simultaneously inside of it. The most important part of libuv is the event loop. It’s a loop on which libuv is constantly checking the queue that something has happened.

When libuv sees something is completed on the queue it processes it and runs a callback. A callback is some code that should runs when certain code is finished running. Similar to an event listener.

Essentially the process is libuv sends a request to the operating system. The operating system adds the event to the queue. Once the event is completed in the queue the libuv event loop checks to see what events are completed and initiates callback function from the V8 engine of completed events. This happens synchronously one at a time on Node.js but also happens asynchronously since Node and V8 are running at the same time.

Event-driven non-blocking I/O in V8 JavaScript is commonly referenced in Node.js. Non-blocking means doing other things without stopping your programming from running. Which is made possible by Node’s doing things asynchronously. I/O is in reference to inputs and outputs. The event driven part is in reference to Node being able to listen and run system events and custom events at the same time.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Up ↑

%d bloggers like this: