Creating a Feathers Application
The foundation of every Feathers application starts with thefeathers() function, which creates a new application instance.
EventEmitter and provides the core functionality for registering services, configuring middleware, and managing application lifecycle.
Application Settings
Feathers applications use a simple key-value store for configuration settings, similar to Express.1
Set Configuration Values
Use
app.set() to store configuration values:2
Retrieve Configuration Values
Use
app.get() to retrieve stored values:3
Chain Method Calls
The
set() method returns the app instance, allowing method chaining:Using Express with Feathers
For HTTP/REST APIs, Feathers integrates seamlessly with Express, combining Feathers services with Express middleware.Application Configuration
Theconfigure() method allows you to organize application setup into reusable configuration functions.
Configuration Pattern
this is also bound to the app, giving you flexibility in how you access it.
Application Lifecycle
Feathers provides lifecycle methods to manage your application’s startup and shutdown processes.1
Setup Phase
The
setup() method is called when the server starts and triggers the setup() method on all registered services:2
Teardown Phase
The
teardown() method gracefully shuts down the application and all services:3
Setup Hooks
You can also add hooks to the setup and teardown lifecycle:
Starting the Server
For Express-based applications, use thelisten() method to start the HTTP server:
Starting the Server
listen() method automatically calls setup() on the application and all registered services.
Event Emitter
Since Feathers applications extend Node’sEventEmitter, you can listen to and emit custom events:
Using Events
Sub-Applications
You can mount entire Feathers applications as sub-applications to create modular API structures:Sub-Applications
The
listen() method is specific to Express-based applications. For Socket.io or other transports, you’ll need to set up the server manually and call app.setup(server) explicitly.Complete Example
Here’s a complete example bringing together all the setup concepts:Complete Application Setup