@feathersjs/socketio package provides real-time functionality using Socket.io, enabling bidirectional communication between clients and your Feathers services.
Installation
Basic Setup
Complete Example
With Express Integration
Socket.io works seamlessly with Express:Socket.io Configuration
Customize Socket.io server options:- Basic Options
- Custom Port
- Configuration Callback
- With Options and Callback
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
- Browser Client
- With Authentication
- Query Parameters
Connect from the browser:
Real-Time Events
Services automatically emit real-time 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:port- Optional port number for Socket.io serveroptions- Socket.io ServerOptionscallback- Function called with Socket.io server instance
Middleware Types
FeathersSocket: Extended Socket.io socket with Feathers params:Performance Tips
-
Set Max Listeners: Prevent memory leaks with many services
-
Use Channels Efficiently: Only send events to relevant clients
-
Enable Compression: Reduce bandwidth usage
-
Adjust Timeouts: Tune for your use case