LEARNNode CLI Automation

Node.js Event Loop

If you are new to Node.js then there is a strong chance that you never heard of its Event Loop. It is one of the core concepts of Node.js that you need to understand if you want to build production-quality CLIs. So in this article, I am going to talk a little bit about the Node.js event loop to give you a basic understanding.

What is Event Loop?

JavaScript is actually a single-threaded language. But Node.js has the ability to perform multiple I/O operations. It does this by offloading these processes to a system kernel whenever it is possible.

The Node.js event loop gets triggered by whatever file is trying to run the Node.js. In our case, it is the index.js file that has our CLI. And it will run a particular event loop. A Node.js process will begin and it will loop around a bunch of processes. When everything is done, it will go ahead and exits itself.

There is a great explanation about the Node.js process by one of its core contributors. I will highly recommend to check it out.

Wrapping Up

This is just an overview of the Node.js event loop. There is still a lot to it. So I would recommend you to read Node.js event loop documentation which you can find here.

Posted by Saad (It's a work in progress: Needs copy editing review by Awais.)