Skip to main content

Express Transport

The @feathersjs/express module provides Express framework bindings and a REST API provider for Feathers applications.

Installation

feathersExpress()

Creates a Feathers application that extends an Express app with Feathers functionality.

Signature

FeathersApplication
A Feathers application instance to extend with Express functionality
Express
An Express application instance (defaults to express())

Returns

Application<S, C>
Combined Express and Feathers application with extended functionality including:
  • All Express app methods and middleware
  • All Feathers service and hook capabilities
  • Enhanced listen() method that calls Feathers setup()
  • Enhanced use() method that handles both Express middleware and Feathers services

Example

rest()

Configures the REST transport provider for Feathers services.

Signature

RestOptions | RequestHandler
REST configuration options or a custom formatter function

RestOptions

RequestHandler
Custom response formatter middleware (defaults to JSON formatter)
AuthenticationSettings
Authentication configuration for parsing credentials from HTTP requests

Example

errorHandler()

Express error handling middleware that formats Feathers errors.

Signature

ErrorHandlerOptions
Error handler configuration options

ErrorHandlerOptions

string
Path to public directory for HTML error pages
boolean | { error?: Function, info?: Function }
Logger configuration for error logging
object | Function
HTML error page configuration or custom handler function
object | Function
JSON error response configuration or custom handler function

Example

notFound()

Middleware that creates a NotFound error for unmatched routes.

Signature

boolean
default:"false"
Include the requested URL in the error message

Example

authenticate()

Express middleware for authenticating requests.

Signature

string | AuthenticationSettings
Authentication service name or settings object
string[]
Authentication strategies to use

AuthenticationSettings

string
Name of the authentication service
string[]
Array of authentication strategy names

Example

parseAuthentication()

Middleware that parses authentication credentials from HTTP headers.

Signature

AuthenticationSettings
Authentication parsing configuration

Example

Exported Express Utilities

The module also exports commonly used Express utilities:

Service Options

Express-specific service options can be configured when registering services:
RequestHandler[]
Middleware to run before the service handler
RequestHandler[]
Middleware to run after the service handler

Request Extensions

The Express request object is extended with Feathers-specific properties:
Params
Feathers params object containing provider, headers, and other metadata
RouteLookup
Service route lookup information

Response Extensions

The Express response object is extended with:
any
The service method result data
HookContext
The hook context from the service call