Skip to main content

Command Palette

Search for a command to run...

Event Loop In Node Js

NodeJs Part 3

Updated
2 min read
Event Loop In Node Js
D

Experienced Consultant, Full Stack Developer, R&D Engineer who loves to solve puzzles & technology problems by code/

The event loop is a crucial part of how Node.js works. It is what allows Node.js to perform non-blocking I/O operations, even though JavaScript is a single-threaded language.

Working:

  • Node.js has a single main thread that executes JavaScript code, and it also has a background thread that manages the event loop. The event loop continuously checks a queue of tasks to see if any of them are ready to be executed.

  • When a task is added to the queue, the event loop will pick it up and execute it when the task's turn comes up. This happens asynchronously, meaning that the main thread is not blocked while the task is being executed.

  • Several types of tasks can be added to the queue, including I/O tasks, timers, and process-related tasks. The event loop ensures that these tasks are executed in a predictable order, allowing for non-blocking behavior.

Note:

  • It's important to note that the event loop is not a separate process or thread. It is simply a mechanism that allows Node.js to efficiently manage the execution of async tasks.

That's a high-level overview of how the event loop works in Node.js. It's a complex system, but understanding it is key to understanding how Node.js works and how to write efficient code that takes advantage of its non-blocking capabilities.

Thanks for reading ❤️

Any other inputs or recommendations feel free to share below

Follow me via Twitter, Github, Instagram

Node.js Concepts

Part 3 of 8

In this series I will be writing about node js concepts in form of minimal blogs which would help you in understanding the various concepts of node.js

Up next

Event Handler in NodeJs

NodeJs Part 4

More from this blog

Dhanush N

56 posts

Experienced Consultant & Software Engineer with experience around building and scaling applications over various emerging technologies. I love solving puzzles & provide technological solutions by code