Skip to main content

What We’ll Build

In this tutorial, we’ll build a real-time chat application with:
  • User authentication (JWT)
  • Real-time messages via Socket.io
  • User management
  • Message history with pagination
  • Type-safe TypeScript throughout
This tutorial covers core Feathers concepts by building a real application. We’ll use actual code from the Feathers framework source.

Prerequisites

  • Node.js 20 or later
  • Basic TypeScript/JavaScript knowledge
  • Familiarity with async/await

Project Setup

1

Initialize the project

Create a new Feathers application:
When prompted:
  • Choose TypeScript
  • Select Express as the HTTP framework
  • Choose Memory for the database (for simplicity)
  • Select Local Authentication (username/password)
2

Install dependencies

The CLI installs dependencies automatically, but you can also install them manually:
3

Project structure

Your project structure should look like:

Building the Application

1. Create the Feathers App

Let’s start by creating the main application instance:
src/app.ts
This creates an Express-compatible Feathers application, just like in the source:
packages/express/src/index.ts

2. Create the Users Service

Users need to authenticate, so let’s create a users service:
src/services/users/users.schema.ts
src/services/users/users.service.ts
The memory adapter implements all CRUD methods:
packages/memory/src/index.ts

3. Create the Messages Service

Now let’s create the messages service:
src/services/messages/messages.schema.ts
src/services/messages/messages.service.ts

4. Set Up Authentication

Add JWT authentication:
src/authentication.ts
The authentication service from the source:
packages/authentication/src/service.ts

5. Wire Everything Together

Update your main app file:
src/app.ts
src/index.ts

6. Test the Application

Start your server:
Test the API:

Real-time Client

Create a simple HTML client to test real-time features:
public/index.html

Advanced Features

Custom Hooks

Create reusable hooks for common tasks:
src/hooks/log.ts

Schema Validation

Use TypeBox schemas for validation:
src/services/messages/messages.hooks.ts

What You’ve Learned

Services are the core abstraction in Feathers. They handle data operations and automatically expose REST and real-time APIs.
Hooks are middleware that run before, after, or around service methods. They’re perfect for validation, authorization, and data transformation.
Feathers provides a flexible authentication system with JWT tokens and multiple strategies.
Socket.io integration gives you real-time capabilities out of the box. Events are automatically sent when data changes.

Next Steps

Add a Database

Replace the memory adapter with MongoDB or PostgreSQL

File Uploads

Handle file uploads with multipart/form-data

Email Verification

Add email verification for new users

Deploy

Deploy your app to production
The complete source code for this tutorial is available in the Feathers repository. Check out the test files for more examples!