Skip to main content

More about Node.js

Learn Node.js

More about Node.js

Hello Folks! Welcome to the part 2 of the Introduction to Node.js blog. Before you read this blog further, it is must to read the previous blogs for better understanding. Here is the Introduction to Node.js link. So let's proceed to learn node.js. In this post we will mainly discuss on node.js architecture, the event loop and the thread pool.

 Node.js Architecture:

As said before, Node.js is  majorly dependent upon the Chrome's V8 engine and LIBUV library for its working. Now I guess you know what is V8 Engine and LIBUV library from the Part 1 of this blog. It is to be mentioned that LIBUV is a library in Node.js which is written in C++ and V8 Engine also uses C++ besides using JavaScript. Therefore, Node.js is not just JavaScript as you might have thought.
Now, its time for us to discuss in detail the "Event Loop" and the "Thread Pool" in Node.js.
The Event Loop enables Node.js to perform non-blocking I/O operations in Node.js, even though Node.js is single threaded. The Event Loop is responsible for executing lighter tasks like executing callbacks and network I/O. The Thread Pool in the other hand is responsible for doing heavy tasks line Compression, Cryptography etc.

The Thread Pool:

When we run Node.js in our computer, it's a process which runs in our computer.The process is nothing but an executing program which gets executed in our local computer. When such a process runs, it runs in single thread. Thread is nothing but a sequence of instructions, which are dedicated to perform a given task. We need not to go deep into the thread and process concepts but the necessary parts will be discussed as and when required. But let us remember that as Node.js runs on single thread we must try not to block the thread, no matter how many users or clients access our web application.
When a program is initialized, all the code gets executed apart from the codes , which are inside any callback functions. All the necessary modules are required and the callbacks are registered. Thereafter, the event loop starts running. Thought this event loop will be discussed after this, but for now keep in mind that the "Event-Loop" is the heart of the entire Node.js architecture. It is responsible for major tasks performed in our application.
But sometimes, the tasks are too heavy to be performed by the main thread of Node.js instantly and it then tends to block the execution. The solution to this is the "Thread Pool". It is basically a set of 4 additional threads provided by the LIBUV library. When a heavy task appears, the main thread offloads it to the additional threads to execute it. The heavy tasks like dealing with file system API, compression, cryptography and DNS lookups are offloaded generally. All of these are handled by Node alone. I hope now you have a little idea about the Thread Pool. So, let's talk about the Event Loop.

The Event Loop: 

As mentioned in the previous section, the event loop is the heart of the Node.js application. The codes which are in the callback functions runs in the event loop.The event loop is also responsible for handling the offloaded tasks. So, let's see how it works.
Node.js has an event triggered architecture as it uses a lot of these callback functions. If you don't come here from a JavaScript background then here is the definition of callback function. A callback function gets executed as a work gets finished. Soon after a work is done, an event is emitted. The event listener listens to those events and accordingly trigger their respective callback functions. This is how Node.js remains asynchronous. If you want to know more, you can refer to the Node.js documentation at https://nodejs.org/en/docs/ 

Hope you like the More about Node.js. To learn more follow the next blogs.
Visit : How to download Node.js in windows ?

Comments

  1. I have read your blog post on. I am very much pleased with the contents you have mentioned.
    Node JS Online training
    Node JS training in Hyderabad

    ReplyDelete
  2. Node.Js development has become very popular over the last four years and continues to stand the competition in 2021, making startups worldwide choose it over other available options.
    Dark Bears is the top Mobile App Development Company in USA.
    Hire node js experts from Dark Bears and infuse Nodejs in your business better experience.

    ReplyDelete
  3. I need to thank you for this very good read and i have bookmarked to check out new things from your post. Thank you very much for sharing such a useful article and will definitely saved and revisit your site.
    Hire Node.Js App Developers

    ReplyDelete

  4. Incredible data in this Post. Keep it up. Much obliged for sharing Love to understand it, Waiting For More new Update and I Already Read your Recent Post its Great Thanks,
    6 Reasons You Need An Android App For Your Business

    ReplyDelete
  5. Very informative post....!

    More about Node.js

    Good for students & learners.....

    Well, we are here to share our Microsoft Web Development

    microsoft application development

    ReplyDelete
  6. Thanks for sharing informative article with us. You can contact offshore software development company from here.

    ReplyDelete

Post a Comment

Popular Posts

Introduction to Node.js

Introduction to Node.js Hello Folks! This blog is for the new Node.js enthusiasts who wants to learn node.js . Here you will learn node.js online from me and you will learn node.js for free . I will guide on how to learn node.js and will help you to learn node.js from scratch. Prerequisites:  Welcome to the world of Back-end web development. Throughout this blog posts, I will guide you to become a backend developer . Before we dive deep into the topic, let us brush up the prerequisites. A website has 2 parts, the "Frontend" and the "Backend" . The Front-end of a website generally refers to the side of the website with which the user interacts. It's the User Interface(U.I.)  of the website. In simple terms, it consists of all those elements which we see and interact with after the web page loads in our computer. It is sometimes also known as "Client-side" of the web page. The Backend web development refers to the server-

Download Node.js for Windows

Hello Folks! If you have not read the previous two blogs, I will highly encourage you to go and read them, before you start with this. Introduction to Node.js More about Node.js We have learned a lot of theories and now its time to get our hands dirty. We will download node.js in this post. Though we will again discuss some theories in the later posts, in this blog I will teach you, how to download node.js and configure your computer to follow the later blogs. I will discuss it in step by step and I will highly recommend you to follow the steps with me. Step -1: First visit the website :  https://nodejs.org/en/   Something like this will be shown : See, by default as my PC has Windows 8.1 and it has 64 bit architecture so I can download from  here. Major  Node .  js versions  enter  Current  release status for six months, which helps library authors time to contribute.  LTS  release status is "long-term support", which generally guarantees that b