From the course: Node.js Essential Training
Unlock the full course today
Join today to access over 24,300 courses taught by industry experts.
Consuming a module with EventEmitter - Node.js Tutorial
From the course: Node.js Essential Training
Consuming a module with EventEmitter
- [Instructor] Let's make some adjustments to our collectAnswers function. And the first thing we want to do here is we want to require the EventEmitter and we're going to destructure this from the events module. So I only want to use event emitter. I don't have to use events.EventEmitter every time. Once I've imported this, I can make some adjustments to our function. The first thing we want to do is include the emitter which will be a new instance of the EventEmitter. And we'll call that there. And then down here at the end of our function, we want to return the emitter so that we can use it. So now we can use this emitter to raise events when certain things happen within this function. For example, let's say we wanted to raise an event every time the user answered a question. What we can do is say emitter.emit answer with whatever that answer is. So what we can do now over in our ask function, we want to be able to…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
(Locked)
Understanding core modules3m 6s
-
(Locked)
Collecting information with readline1m 38s
-
(Locked)
Using readline4m 58s
-
(Locked)
Exporting custom modules3m 17s
-
(Locked)
Creating a module3m 40s
-
(Locked)
Custom events with the EventEmitter1m 45s
-
(Locked)
Consuming a module with EventEmitter2m 22s
-
(Locked)
-
-