Node.js Lesson: Internals of Nodejs: Event Loop

Node.js Lesson: Internals of Nodejs: Event Loop

This Node.js lesson will continue the last lesson where we learned how the LibUV library works internally. We will learn about Event Loop and understand various terms like call stack, callback queue, etc. Let’s start.

Hey everyone, this lesson will continue the last lesson where we learned how the LibUV library works internally. In this lesson, we will learn about Event Loop and understand various terms like call stack, callback queue, etc. Let’s start.

What is Call Stack

JavaScript is a single-threaded language, which means it can do one thing at a time. This also means that it has a single Call Stack. Now, what is a Call Stack?

A call stack is a data structure that holds information about what line of the function is currently being executed. A call stack is used to keep method calls, and it follows the LIFO (Last In First Out) data structure. By LIFO, we mean a container where the last item entered will be the first to get out. There is only one entry from the top, and if you want to take the item at the end, you will have to take everything on top first. If you’re thinking about a box of Pringles, then you’re absolutely correct.

Let’s understand how this call stack holds method calls:

Callback excallidraw example

Callback excallidraw example

The execution will go on like this:

  1. We call the main() function, it gets pushed into the call stack.
  2. This will call the add() function and push it to call stack.
  3. Once it hit return, add() will be popped out from the call stack.
  4. Finally, the main() will be popped out.

node nodejs javascript programming

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

Node.js Lesson: Internals of Nodejs: LibUV

In this Node.js Lesson, 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.

Build Restful APIs with Nodejs from Scratch | Node.js Training

This Edureka Live video on 'How to build CRUD REST API using Node.js'' will help you understand the concept of RESTful APIs and how you can create one using Node.js and Express.js.

JavaScript Full Course - Beginner's Guide to JavaScript on Node.js

This complete 51-part JavaScript tutorial for beginners will teach you everything you need to know to get started with the JavaScript on Node.js. JavaScript Full Course - Beginner's Guide to JavaScript on Node.js

Node.js Lesson: Debugging in Node.js

In this Node.js lesson, we will learn about debugging a Node application. We will learn about different ways which can be employed to debug Node application with ease. Here’s a list of things we will cover in this article: JavaScript Debugger, Chrome DevTools, –inspect command, –inspect-brk command, IDE

Load the C/C++ code in JavaScript programs using Node’s N-API

In this article, we are going to get ourselves familiar with the mechanism and tools to load the C/C++ code dynamically in JavaScript programs using Node’s N-API.