From the course: Node.js Essential Training
Unlock the full course today
Join today to access over 23,700 courses taught by industry experts.
Custom events with the EventEmitter - Node.js Tutorial
From the course: Node.js Essential Training
Custom events with the EventEmitter
- Earlier we had created this collect answers function and what we want to do next with it is we want to break it down into different modules. The first thing we'll do is inside of the start folder we will create a new folder called lib. And this is going to be a library folder that will contain other functions that we can use in different places. So here we want to call this collect answers js. Collect answers js is going to be responsible for housing, this collect answers function. Which really requires several things. So we're going to start to break down this file. We'll cut everything from line 24 and up and drop it here into the collect answers file. The next thing we'll do, is we still want to import read line. We still want to create our interface. But we want to make this consumable by another file. So we're going to replace this function. We'll save module dot exports. We'll set this equal to our function and…
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)
-
-