Skip to main content
Feathers provides a powerful real-time event system built on Node’s EventEmitter. Services automatically emit events when data changes, enabling real-time applications with minimal code.

How Events Work

Every service is an EventEmitter and automatically emits events for data-modifying methods:
service.ts:17-24

Listening to Events

Service Events

Listen to events on a specific service:

Event Callback Parameters

Event listeners receive two parameters:
events.ts:18

Multiple Records

When operations affect multiple records, events are emitted for each:
events.ts:16-19

Custom Events

Define custom events for your service:
service.ts:45-47
Custom events defined in the events option are merged with default events (created, updated, patched, removed).

Controlling Event Emission

Set Event in Hook Context

Control which event is emitted using the context.event property:
events.ts:6-21

Disable Events

Set context.event = null to prevent event emission:

Service Events Configuration

Customize the complete list of events a service emits:

Real-Time with Transports

Events are automatically sent to connected clients via transports:

Event Filtering & Publishing

Control which clients receive events using publishers:
Publishing requires a transport like @feathersjs/socketio or @feathersjs/primus and channel configuration.

Event Patterns

Notifications

Audit Logging

Cache Invalidation

Webhook Triggers

Data Synchronization

Events vs Hooks

Use events when:
  • You need to react to changes after they happen
  • Multiple independent systems need to know about changes
  • You’re building real-time features
  • You need loose coupling between services
  • You want to broadcast to multiple clients

Event Mixin

Feathers automatically adds EventEmitter functionality to services:
events.ts:23-31

Best Practices

  1. Keep event handlers lightweight - Don’t block the event loop
  2. Handle errors in listeners - Wrap async operations in try/catch
  3. Avoid circular dependencies - Don’t call service methods that emit the same event
  4. Use custom events for domain events - Make events meaningful
  5. Clean up listeners - Remove listeners when components unmount
  6. Test event handlers - Unit test event logic separately
  7. Document custom events - Make it clear what events services emit

Debugging Events

Enable debug logging for events:

Next Steps

Errors

Learn about error handling in Feathers

Real-time Transport

Control event distribution with Socket.io channels