The foundation of every Feathers application starts with the feathers() function, which creates a new application instance.
import { feathers } from '@feathersjs/feathers'const app = feathers()
The application instance extends Node’s EventEmitter and provides the core functionality for registering services, configuring middleware, and managing 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:
app.use('/users', { async setup(app, path) { console.log(`Setting up service at path: ${path}`) // Initialize database connections, caches, etc. }, async get(id) { return { id } }})// Start the server and trigger setupconst server = await app.listen(3030)
2
Teardown Phase
The teardown() method gracefully shuts down the application and all services:
For Express-based applications, use the listen() method to start the HTTP server:
Starting the Server
const port = app.get('port') || 3030const host = app.get('host') || 'localhost'const server = await app.listen(port)console.log(`Feathers app started on http://${host}:${port}`)// The server is available as app.serverprocess.on('SIGTERM', async () => { await app.teardown() process.exit(0)})
The listen() method automatically calls setup() on the application and all registered services.
You can mount entire Feathers applications as sub-applications to create modular API structures:
Sub-Applications
import { feathers } from '@feathersjs/feathers'// Create a sub-applicationconst apiV2 = feathers()apiV2.use('/users', userServiceV2)apiV2.use('/posts', postServiceV2)// Mount sub-app with prefixapp.use('/api/v2', apiV2)// Services are now available at:// - /api/v2/users// - /api/v2/posts
When mounting a sub-application, all its services are automatically registered with the combined path prefix.
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.