Skip to main content
The @feathersjs/socketio package provides real-time functionality using Socket.io, enabling bidirectional communication between clients and your Feathers services.

Installation

Basic Setup

1

Import Socket.io configuration

Import the Socket.io configurator from the package:
2

Configure the transport

Add Socket.io to your application:
3

Register services

Services are automatically available through Socket.io:
4

Start the server

Listen on a port to start the Socket.io server:

Complete Example

With Express Integration

Socket.io works seamlessly with Express:

Socket.io Configuration

Customize Socket.io server options:
Pass Socket.io server options directly:

Middleware

Socket.io middleware runs when clients connect:

Socket Parameters

Customize parameters passed to services from socket connections:

Authentication

Integrate authentication with Socket.io:

Client Usage

Connect from the browser:

Real-Time Events

Services automatically emit real-time events:
Clients receive these events:

Connection Management

Track and manage socket connections:

Channels and Publishing

Control which connections receive real-time events:

Custom Events

Send custom events to clients:

Error Handling

Handle errors in Socket.io connections:

TypeScript Support

API Reference

socketio(callback?)

Configures Socket.io transport. Signature:
Parameters:
  • port - Optional port number for Socket.io server
  • options - Socket.io ServerOptions
  • callback - Function called with Socket.io server instance

Middleware Types

FeathersSocket: Extended Socket.io socket with Feathers params:
NextFunction:

Performance Tips

  1. Set Max Listeners: Prevent memory leaks with many services
  2. Use Channels Efficiently: Only send events to relevant clients
  3. Enable Compression: Reduce bandwidth usage
  4. Adjust Timeouts: Tune for your use case