Key Concepts

Review core concepts you need to learn to master this subject

The events Module

// Require in the 'events' core module let events = require('events'); // Create an instance of the EventEmitter class let myEmitter = new events.EventEmitter(); let version = (data) => { console.log(`participant: ${data}.`); }; // Assign the version function as the listener callback for 'new user' events myEmitter.on('new user', version) // Emit a 'new user' event myEmitter.emit('new user', 'Lily Pad') // 'Lily Pad'

Node.js has an EventEmitter class which can be accessed by importing the events core module by using the require() statement. Each event emitter instance has an .on() method which assigns a listener callback function to a named event. EventEmitter also has an .emit() method which announces a named event that has occurred.

Node.js Essentials
Lesson 1 of 1
  1. 1
    We will continue learning Node.js in this lesson by going into depth, covering modules essential to back-end development with Node.js. We’ll cover core Node.js modules such as events, error, buffer…
  2. 2
    Node is often described as having event-driven architecture. Let’s explore what that means. In traditional imperative programming, we give the computer a series of instructions to execute in a pr…
  3. 3
    If you’ve worked with JavaScript before, you’re likely familiar with the concept of input/output even if you haven’t heard it called that. At its most abstract, output is any data or feedback tha…
  4. 4
    The Node environment’s error module has all the standard JavaScript errors such as EvalError, SyntaxError, RangeError, ReferenceError, TypeError, and URIError as well as the JavaScript Error class …
  5. 5
    In Node.js, the Buffer module is used to handle binary data. The Buffer module is within the global scope, which means that Buffer objects can be accessed anywhere in the environment without import…
  6. 6
    All of the data on a computer is organized and accessed through a filesystem. When running JavaScript code on a browser, it’s important for a script to have only limited access to a user’s filesy…
  7. 7
    In the previous exercise, we practiced reading the contents of entire files into our JavaScript programs. In more realistic scenarios, data isn’t processed all at once but rather sequentially, piec…
  8. 8
    In the previous exercise, we were reading data from a stream, but we can also write to streams! We can create a writeable stream to a file using the fs.createWriteStream() method: const fs = requi…
  9. 9
    There are times when we want some of our code to be executed at a specified point in time. This is what the timers module is used for. L…
  10. 10
    Congratulations on making it to the end! Let’s take a moment to review the content covered in this lesson: - Blocking code runs synchronously and non-blocking code, such as timer functions, runs a…

What you'll create

Portfolio projects that showcase your new skills

Pro Logo

How you'll master it

Stress-test your knowledge with quizzes that help commit syntax to memory

Pro Logo