Close Menu
Soshace Digital Blog

    Subscribe to Updates

    Get The Latest News, Updates, And Amazing Offers

    What's Hot
    JavaScript

    Top AngularJS interview questions

    Development

    Enhancing Software Performance: Strategies for Optimal Speed

    JavaScript

    Why Using Node.js for Developing Web Applications Makes Perfect Sense

    Important Pages:
    • Home
    • About
    • Services
    • Contact Us
    • Privacy Policy
    • Terms & Conditions
    Facebook X (Twitter) Instagram LinkedIn YouTube
    Today's Picks:
    • Scaling Success: Monitoring Indexation of Programmatic SEO Content
    • Leveraging Influencers: Key Drivers in New Product Launches
    • How Privacy-First Marketing Will Transform the Industry Landscape
    • The Impact of Social Proof on Thought Leadership Marketing
    • Balancing Value-Driven Content and Promotional Messaging Strategies
    • Top Influencer Marketing Platforms to Explore in 2025
    • Emerging Trends in Marketing Automation and AI Tools for 2023
    • Strategies to Mitigate Duplicate Content in Programmatic SEO
    Wednesday, September 10
    Facebook X (Twitter) Instagram LinkedIn YouTube
    Soshace Digital Blog
    • Home
    • About
    • Services
    • Contact Us
    • Privacy Policy
    • Terms & Conditions
    Services
    • SaaS & Tech

      Maximizing Efficiency: How SaaS Lowers IT Infrastructure Costs

      August 27, 2025

      Navigating Tomorrow: Innovations Shaping the Future of SaaS

      August 27, 2025

      Maximizing Impact: Strategies for SaaS & Technology Marketing

      August 27, 2025
    • AI & Automation

      Enhancing Customer Feedback Analysis Through AI Innovations

      August 27, 2025

      Navigating the Impact of AI on SEO and Search Rankings

      August 27, 2025

      5 Automation Hacks Every Home Service Business Needs to Know

      May 3, 2025
    • Finance & Fintech

      Critical Missteps in Finance Marketing: What to Avoid

      August 27, 2025

      Analyzing Future Fintech Marketing Trends: Insights Ahead

      August 27, 2025

      Navigating the Complex Landscape of Finance and Fintech Marketing

      August 27, 2025
    • Legal & Compliance

      Exploring Thought Leadership’s Impact on Legal Marketing

      August 27, 2025

      Maximizing LinkedIn: Strategies for Legal and Compliance Marketing

      August 27, 2025

      Why Transparency Matters in Legal Advertising Practices

      August 27, 2025
    • Medical Marketing

      Enhancing Online Reputation Management in Hospitals: A Guide

      August 27, 2025

      Analyzing Emerging Trends in Health and Medical Marketing

      August 27, 2025

      Exploring Innovative Content Ideas for Wellness Blogs and Clinics

      August 27, 2025
    • E-commerce & Retail

      Strategic Seasonal Campaign Concepts for Online and Retail Markets

      August 27, 2025

      Emerging Trends in E-commerce and Retail Marketing Strategies

      August 27, 2025

      Maximizing Revenue: The Advantages of Affiliate Marketing for E-Commerce

      August 27, 2025
    • Influencer & Community

      Leveraging Influencers: Key Drivers in New Product Launches

      August 27, 2025

      Top Influencer Marketing Platforms to Explore in 2025

      August 27, 2025

      Key Strategies for Successful Influencer Partnership Negotiations

      August 27, 2025
    • Content & Leadership

      The Impact of Social Proof on Thought Leadership Marketing

      August 27, 2025

      Balancing Value-Driven Content and Promotional Messaging Strategies

      August 27, 2025

      Analyzing Storytelling’s Impact on Content Marketing Effectiveness

      August 27, 2025
    • SEO & Analytics

      Scaling Success: Monitoring Indexation of Programmatic SEO Content

      August 27, 2025

      Strategies to Mitigate Duplicate Content in Programmatic SEO

      August 27, 2025

      Effective Data Visualization Techniques for SEO Reporting

      August 27, 2025
    • Marketing Trends

      How Privacy-First Marketing Will Transform the Industry Landscape

      August 27, 2025

      Emerging Trends in Marketing Automation and AI Tools for 2023

      August 27, 2025

      Maximizing ROI: Key Trends in Paid Social Advertising

      August 27, 2025
    Soshace Digital Blog
    Blog / JavaScript / Node.js / Node.js Lessons / Nodejs Lesson 15: Internals of Nodejs: LibUV
    Node.js

    Nodejs Lesson 15: Internals of Nodejs: LibUV

    Mohammad Shad MirzaBy Mohammad Shad MirzaFebruary 4, 2021Updated:March 9, 2021No Comments5 Mins Read
    Facebook Twitter Pinterest Telegram LinkedIn Tumblr Email Reddit
    Nodejs Lesson 15: Internals of Nodejs: LibUV
    Nodejs Lesson 15: Internals of Nodejs: LibUV
    Share
    Facebook Twitter LinkedIn Pinterest Email Copy Link
    Nodejs Lesson 15: Internals of Nodejs: LibUV
    Nodejs Lesson 15: Internals of Nodejs: LibUV

    Hello everyone, today we are going to talk about the internals of Nodejs. This article will guide how node js works and how it can handle async tasks. What will happen if ten requests come at once? Will it handle one request and discard the other 9? or will it create a queue and serve each one by one. We will answer all these questions in this and coming lesson. Let’s start.

    The main engine behind Nodejs: LibUV

    LibUV is the core engine that powers Nodejs. LibUV provides support for asynchronous I/O operations. It’s a C based library primarily created for Nodejs and used by Luvit, Julia, pyuv, and some other software.

    LibUV enforces an asynchronous, event-driven style of programming. It uses event loops to handle asynchronous tasks effectively. It also supports non-blocking network support, asynchronous file system access, etc.

    By “event-driven” programming, we mean it watches for events to occur and then handle them when they occur. As we saw in the Event Emitter lesson earlier, we created an event listener who was “listening” to the event. We then wrote a handler function, which got called when that particular event occurs. The monitoring of events happening in the system is managed by LibUV using something that we call Event Loop. This Event Loop usually keeps running forever.

    The responsibilities of LibUV are cross-platform input-output operations, handling files & networks, and support the event loop. You’re not going to interact with these yourself. Still, this knowledge is good to have to understand the working of Nodejs better. We will learn about Event Loops in the next lesson so let’s know the other now.

    A few essential concepts in LibUV

    To understand LibUV better, we will have to understand the following three concepts first and then about more on LibUV by keeping these three in mind.

    LibUV provides two abstractions to work with: handles and requests.

    1. Handles: Handles represent long-lived objects capable of performing certain operations while active. When it completes the job, handles will invoke the corresponding callbacks. As long as a handle is active, the event loop will continue running. Some examples of handles are TCP servers that get their connection callback called every time there is a new connection, timers, signals, and child processes.
    2. Requests: Abstractions for short-lived operations. In contrast to handles that are considered as objects, requests can be thought of as functions or methods. Requests are used to write data on handles. Like handles, active requests will also keep the event loop alive.Another essential concept in LibUV is thread pool. LibUV delegates all the heavy work to a pool of worker threads.
    3. Thread pool: The thread pool takes care of the file I/O and DNS lookup. All the callbacks, however, are executed on the main thread. Since Node 10.5, worker threads can also be used by the programmer to run Javascript in parallel.
    Read More:  MongoDb. Capped collections

    More on working with threads in LibUV

    The libuv module has a responsibility that is relevant for some particular functions in the standard library. For some standard library function calls, the node C++ side and libuv decide to do expensive calculations outside of the event loop entirely. LibUV creates something called a thread pool. This thread pool consists of four threads by default. These threads can be used for running computationally intensive tasks such as hashing functions. Many of the functions included in the standard node library will automatically make use of this thread pool.

    If you have too many function calls, It will use all of the cores. CPU cores do not actually speed up the processing function calls. They allow for some amount of concurrency inside of the work that you are doing.

    libuv doesn’t use thread for asynchronous tasks, but for those that aren’t asynchronous by nature. As an example, it doesn’t use threads to deal with sockets. It uses threads to make synchronous fs calls asynchronous.

    The I/O (or event) loop is the central part of libuv. It establishes the content for all I/O operations, and it’s meant to be tied to a single thread. One can run multiple event loops as long as each runs in a different thread.

    LibUV helps in handling:

    1. File I/O includes file watching, file system operations, etc
    2. Child processes (the child-process module in Node)
    3. A pool of worker threads to handle blocking I/O tasks
    4. Synchronization primitives for threads.

    Let us look at what’s happening at launching a server of this kind as an example:

    const http = require('http');
    const fs = require('fs');
     
    const server = new http.Server();
    
    server.on('request', (req, info) => {
     if (req.url == '/') {
         fs.readFile('index.html', function(err, info) {
             if(err) {
                 console.error(err);
                 res.statusCode = 500;
                 res.end("A server error occurred ");
                 return
             }
    
             res.end("info");
         });
    
     } else { /*404 */ }
    });
     
    server.listen(3000);

    First JavaScript gets active. It connects the modules:

    const http = require('http');  
    const fs = require('fs');

    and it creates an object

    const server = new http.createServer();

    It gives a handler:

    server.on('request', (err, info) => {});

    At this point, it doesn’t matter what is inside the function because a handler hasn’t been activated yet. The last string is a call for the “listen” command.

    server.listen(3000);

    Getting to Node.js, the command goes through its C++ code and becomes an internal method call TCPWrap::listen. This internal method calls uv__listen, which executes the whole work.

    Read More:  Create simple POS with React.js, Node.js, and MongoDB #10: CRUD Supplier
    LibUV working
    LibUV working

    Depending on an operational system, it hangs a connection handler on this port. For instance, the Unix system requires a system call “listen.” So, LibUV appoints a connection handler for this port. This action’s result gets upwards in the chain. That’s it for today. We will learn about Event Loops in the next lesson.

    Source code of the lesson you can find by the link.

    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email
    Mohammad Shad Mirza
    • X (Twitter)
    • LinkedIn

    JavaScript lover working on React Native and committed to simplifying code for beginners. Apart from coding and blogging, I like spending my time sketching or writing with a cup of tea.

    Related Posts

    Mastering REST APIs: Essential Techniques for Programmers

    December 18, 2024

    Crafting Interactive User Interfaces Using JavaScript Techniques

    December 17, 2024

    Effective Strategies for Utilizing Frameworks in Web Development

    December 16, 2024
    Leave A Reply Cancel Reply

    You must be logged in to post a comment.

    Stay In Touch
    • Facebook
    • Twitter
    • Pinterest
    • Instagram
    • YouTube
    • Vimeo
    Don't Miss
    Interview November 29, 2024

    Mastering Common Interview Questions: Strategic Responses Guide

    Mastering common interview questions requires strategic preparation. Understanding the nuances of behavioral, situational, and technical inquiries enables candidates to craft precise, impactful responses, showcasing their skills and alignment with the organization’s objectives.

    Enhancing Online Reputation Management in Hospitals: A Guide

    August 27, 2025

    Работа с заказчиком

    December 31, 2015

    Creating Mock API using Mirage in a React application

    August 12, 2020

    Categories

    • AI & Automation
    • Angular
    • ASP.NET
    • AWS
    • B2B Leads
    • Beginners
    • Blogs
    • Business Growth
    • Case Studies
    • Comics
    • Consultation
    • Content & Leadership
    • CSS
    • Development
    • Django
    • E-commerce & Retail
    • Entrepreneurs
    • Entrepreneurship
    • Events
    • Express.js
    • Facebook Ads
    • Finance & Fintech
    • Flask
    • Flutter
    • Franchising
    • Funnel Strategy
    • Git
    • GraphQL
    • Home Services Marketing
    • Influencer & Community
    • Interview
    • Java
    • Java Spring
    • JavaScript
    • Job
    • Laravel
    • Lead Generation
    • Legal & Compliance
    • LinkedIn
    • Machine Learning
    • Marketing Trends
    • Medical Marketing
    • MSP Lead Generation
    • MSP Marketing
    • NestJS
    • Next.js
    • Node.js
    • Node.js Lessons
    • Paid Advertising
    • PHP
    • Podcasts
    • POS Tutorial
    • Programming
    • Programming
    • Python
    • React
    • React Lessons
    • React Native
    • React Native Lessons
    • Recruitment
    • Remote Job
    • SaaS & Tech
    • SEO & Analytics
    • Soshace
    • Startups
    • Swarm Intelligence
    • Tips
    • Trends
    • Vue
    • Wiki
    • WordPress
    Top Posts

    Optimizing Graphql Data Queries with Data Loader

    GraphQL January 8, 2021

    Create simple POS with React.js, Node.js, and MongoDB #12 : Getting started with React Table

    Node.js August 14, 2020

    Implementing Machine Learning in Web Applications with Python and TensorFlow

    Flask April 7, 2023

    VR and AR in Remote Work: Cases and Trends

    Remote Job February 12, 2019

    Subscribe to Updates

    Get The Latest News, Updates, And Amazing Offers

    About Us
    About Us

    Soshace Digital delivers comprehensive web design and development solutions tailored to your business objectives. Your website will be meticulously designed and developed by our team of seasoned professionals, who combine creative expertise with technical excellence to transform your vision into a high-impact, user-centric digital experience that elevates your brand and drives measurable results.

    7901 4th St N, Suite 28690
    Saint Petersburg, FL 33702-4305
    Phone: 1(877)SOSHACE

    Facebook X (Twitter) Instagram Pinterest YouTube LinkedIn
    Our Picks
    Programming

    Guidelines for Building Accessible Web Applications

    JavaScript

    React Lesson 1: Introduction to React

    Programming

    DigitalOcean vs. AWS: Comparing Offers and Choosing the Better Option

    Most Popular

    Understanding Flutter Bloc Pattern

    Flutter

    React Lesson 13 Part 2: Asynchronous actions

    JavaScript

    React Lesson 5: React Devtools and Reusable Open-Source Components

    JavaScript
    © 2025 Soshace Digital.
    • Home
    • About
    • Services
    • Contact Us
    • Privacy Policy
    • Terms & Conditions

    Type above and press Enter to search. Press Esc to cancel.