Chapter 3. Asynchrony and Events

We learned that the most important concept in Node is its event-driven model, which is also known as the non-blocking model. Node associates asynchronous operations with events and internally takes care of running them independently from other operations. Once an asynchronous operation is done running, Node schedules the execution of your code that depends on that operation.

In this chapter, we’ll expand on the important concepts of events and their handler functions as callbacks, promises, and listeners. We’ll learn how Node manages the scheduling of asynchronous operations with its event loop and event queues, and see examples of how to create and use custom event emitters and listener functions.

Sync vs Async Handling

A web browser is a single-threaded environment where all user-related code runs in one main thread. If you have a slow function in your website, users will not be able to even ...

Get Efficient Node.js now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.