September 2024
Beginner to intermediate
985 pages
35h 37m
English
Much of Node.js is event-driven. The events are triggered by event emitters—that is, objects of the EventEmitter type. In this section, we'll briefly show you how to use this basic programming paradigm (which you already know in principle from Chapter 6) in Node.js.
The EventEmitter type has two main methods (you can see a detailed listing in Table 17.3). The on() method can be used to define callback functions to be executed when a specific event occurs—in other words, event listeners can be registered this way. You can use the second method of EventEmitter, the emit() method, to trigger events.
The first parameter to be passed to the on() method is the ...
Read now
Unlock full access