Skip to main content
Feathers services automatically emit events when resources are created, updated, patched, or removed. This allows you to build real-time applications by listening to these events through various transports.

Default Events

Services automatically emit the following events:
  • created - Emitted after a resource is created
  • updated - Emitted after a resource is updated
  • patched - Emitted after a resource is patched
  • removed - Emitted after a resource is removed
These events are emitted on both the service and the application.

Event Listeners

Services extend Node’s EventEmitter, so you can use all standard EventEmitter methods:

on()

Listen for an event:
string
required
The event name (e.g., 'created', 'patched')
function
required
Callback function that receives the event data and optional hook context

once()

Listen for an event once:

removeListener()

Remove a specific event listener:

removeAllListeners()

Remove all listeners for an event or all events:

Event Emission

Events are automatically emitted after successful service method calls unless:
  1. The service’s events option includes the event name (indicating the service handles emission itself)
  2. The context.event property is set to null in a hook

Automatic Event Emission

Controlling Event Emission

You can control event emission in hooks:

Custom Events

You can define custom events when registering a service:
string[]
List of custom event names. These are merged with the default events (created, updated, patched, removed).

Service Events Configuration

You can completely replace the default events:
string[]
Complete list of events for this service. Unlike events, this replaces the default events entirely.

Event Data

Events receive two arguments:
  1. data - The resource that was created, updated, patched, or removed
  2. context - The hook context (optional)

Multiple Results

When a method returns multiple results (e.g., create with an array), the event is emitted once for each result:

Application-Level Events

The application itself is an EventEmitter and can be used for custom application events:

Real-Time Transports

Events are the foundation for real-time updates in Feathers. When using transports like Socket.io or Primus, service events are automatically sent to connected clients.

Server-Side

Client-Side

Event Filtering

For real-time applications, you often want to filter which clients receive which events. This is done through channels (see Publishing & Channels documentation).

Event Hook

Feathers uses an internal eventHook to handle event emission:

Examples

Audit Logging

Send Notifications

Update Caches

Webhook Integration

Type Definitions