Skip to content
On this page


EventEmitter package provides a simple observer implementation, allowing you to subscribe and listen for various events that occur in your application. Events serve as a great way to decouple various aspects of your application, since a single event can have multiple listeners that do not depend on each other.

EventEmitterModule internally uses the EventTarget API.

Getting started

No need to install an extra module, you can import it from danet/mod.ts

import { EventEmitterModule, EventEmitter } from `danet/mod.ts`

Import the EventEmitterModule into the root AppModule:

import { Module, EventEmitterModule } from 'danet/mod.ts';

  import: [EventEmitterModule],
export class AppModule {}

Dispatching Events

To dispatch (i.e., fire) an event, first inject EventEmitter using standard constructor injection:

constructor(private eventEmitter: EventEmitter) {}

::: Hint 💡 Import the EventEmitter from the danet/mod.ts package. :::

Then use it in a class as follows:

  new OrderCreatedEvent({
    orderId: 1,
    payload: {},

Listening to Events

To declare an event listener, decorate a method with the @OnEvent() decorator preceding the method definition containing the code to be executed, as follows:

class OrderListeners {
    handleOrderCreatedEvent(payload: OrderCreatedEvent) {
      // handle and process "OrderCreatedEvent" event

Warning 🚧

this module does not support wildcard expressions yet.


A working example is available here.