@feathersjs/express package provides seamless integration between Feathers and Express, combining the power of Feathers services with Express’s rich middleware ecosystem.
Installation
Basic Setup
Create the Express application
The Express integration wraps a Feathers application with Express functionality:
Complete Example
Service Middleware
You can add Express middleware before and after service calls:How Middleware Works
- Before Middleware
- After Middleware
Middleware added before the service runs before the service method is called:
Authentication
Integrate Feathers authentication with Express middleware:Authentication Settings
Error Handling
The Express integration provides comprehensive error handling:Not Found Handler
Static Files
Serve static files using Express’s static middleware:Custom Response Formatting
Customize how service results are sent as HTTP responses:Using Existing Express App
You can integrate Feathers into an existing Express application:Express Sub-Apps
Feathers works seamlessly with Express sub-apps and routers:HTTPS Support
Run Feathers with HTTPS:Lifecycle Methods
- listen()
- setup()
- teardown()
The
listen() method starts the server and calls setup() on all services:TypeScript Support
API Reference
express(feathersApp, expressApp?)
Wraps a Feathers application with Express. Parameters:feathersApp- A Feathers application instanceexpressApp- Optional existing Express app
rest(options?)
Configures the REST transport. Options:formatter- Custom response formatter middlewareauthentication- Authentication settingsservice- Authentication service namestrategies- Array of strategy names
errorHandler(options?)
Express error handling middleware. Options:logger- Logger instance or false to disablehtml- HTML error handlers (function or file paths)json- JSON error handlers (function or default)public- Path to public error pages directory
notFound(options?)
Handles 404 errors. Options:verbose- Include URL in error message