Skip to main content
D
Node.js
Node.js Events

Node.js Events

Node.js triggers and listens for custom events.

Read Time
5 min read
Difficulty
Beginner
Last Updated
Jun 15, 2026
Version
v1.0.0

Introduction

Node.js operates on an event-driven architecture. This means the server spends most of its time waiting for specific events to happen, like a file opening or a user logging in. Developers can create their own custom events using the built-in Events module.

Example

Example
1/* this handles an event */
2var events = require('events');
3var eventEmitter = new events.EventEmitter();
4
5eventEmitter.on('login', function () {
6  console.log('User logged in!');
7});
8
9eventEmitter.emit('login');

Key Points

  • The Events module is built into Node.js.
  • The `on()` method listens for an event to happen.
  • The `emit()` method triggers the event manually.
  • Events make handling asynchronous data much easier.

Up Next

Continue your journey with the next topic.

Go to Node Streams