In this video, learn how to add custom events to the collectAnswers module. These custom events will allow consumers to incorporate custom functionality when using the collectAnswers function.
- [Instructor] Back in lesson five of the current chapter, … we took our collectAnswers function … and we turned it into a module … that we can make reusable. … So if you look within your exercise files … under the lib folder, there's a collectAnswers.js, … and this is our module for the collectAnswers function. … We can improve this function by using the EventEmitter. … So I'm going to go ahead and pull in my EventEmitter … by calling const EventEmitter. … Notice this time, I'm destructuring the EventEmitter … right when I require our events module. … That way I can just use it directly … without having to preface it with events dot. … So down here inside of our function, … let's go ahead and create an instance of our emitter. … So we'll create an emitter equals new EventEmitter, … so we're creating an instance of an EventEmitter … by invoking the constructor function. … And then down here at the very end of the function, … let's go ahead and return our emitter. … So now we can use this emitter to raise events …
- What is Node.js?
- Installing Node.js
- The global object
- Importing the core modules
- Creating custom events with the EventEmitter
- Reading, writing, and removing files
- Working with file streams
- Creating child processes with the exec and spawn functions
Skill Level Intermediate
Node.js: Real-Time Web with Socket.IOwith Emmanuel Henri1h 24m Intermediate
1. What Is Node.js?
2. Set Up Your Environnment
3. Node Globals
4. Node Modules
5. File System Basics
6. Files and Streams
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.