Overview
Thefeathers generate service command creates a complete service implementation with database adapter, schema validation, type definitions, and test files. Services are the core building blocks of Feathers applications that handle data operations.
Usage
Options
The name of the service. This will be used for class names, file names, and variable names.Validation: Cannot be empty or “authentication”
The path where the service will be registered on the API. Defaults to kebab-case of the service name.Default:
kebab-case(name) (e.g., “userProfiles” becomes “user-profiles”)Validation: Cannot be empty or “authentication”The service type/database adapter to use.Choices:
knex- SQL databases (PostgreSQL, MySQL, SQLite, MSSQL)mongodb- MongoDB databasecustom- Custom service without database
Interactive Prompts
Service Name
Prompt: “What is the name of your service?” Validation: Cannot be empty or “authentication” The name will be transformed into various formats:- camelCase for variables (e.g.,
userMessages) - PascalCase for classes (e.g.,
UserMessagesService) - kebab-case for files (e.g.,
user-messages.ts)
Service Path
Prompt: “Which path should the service be registered on?” Default: kebab-case version of the service name Example: Service name “messages” defaults to path “messages”, accessible at/messages
Nested paths: You can use slashes for nested paths like api/v1/messages
Authentication
Prompt: “Does this service require authentication?” Default: No If enabled, the service will require users to be authenticated before accessing it.Database Type
Prompt: “What database is the service using?” Choices:- SQL - Uses Knex.js adapter for PostgreSQL, MySQL, SQLite, or MSSQL
- MongoDB - Uses MongoDB adapter
- A custom service - No database, implement custom methods
Schema Format
Prompt: “Which schema definition format do you want to use?” Choices:- TypeBox (recommended) - Type-safe schema with excellent TypeScript support
- JSON schema - Standard JSON schema format
- No schema - Not recommended with a database
Generated Files
For a service named “messages” with MongoDB and TypeBox:With Nested Paths
For pathapi/v1/messages:
Generated Code Examples
Service Class (TypeScript + MongoDB)
Schema Definition (TypeBox)
Service Registration
Terminal Output Example
Service Naming Conventions
The generator creates multiple variations of your service name:Original input name (e.g., “UserMessage”)
Camel case starting with lowercase (e.g., “userMessage”)
Camel case starting with uppercase (e.g., “UserMessage”)
Class name with “Service” suffix (e.g., “UserMessageService”)
Kebab case for files (e.g., “user-message”)
The last element of the path (e.g., “messages”)
Kebab case of the full path (e.g., “api-v1-messages”)
Database Adapters
The generator supports multiple database adapters:Knex (SQL Databases)
Supports:- PostgreSQL
- MySQL/MariaDB
- SQLite
- Microsoft SQL Server
@feathersjs/knex adapter with migrations support.
MongoDB
Generates a service using@feathersjs/mongodb adapter with native MongoDB driver.
Custom
Generates a service with custom methods that you implement yourself. Useful for:- External APIs
- Business logic without database
- Non-standard data sources
Authentication Integration
When authentication is enabled, the generator:- Adds
authenticate('jwt')hook to all methods - Restricts access to authenticated users only
- Populates user information in the hook context
Schema Validation
TypeBox (Recommended)
- Full TypeScript type inference
- Runtime validation
- OpenAPI/JSON Schema compatible
- Excellent developer experience
JSON Schema
- Standard JSON Schema format
- Works with any validation library
- More verbose than TypeBox
No Schema
- No validation or typing
- Not recommended for production
- Use only for prototyping
Testing
The generator creates a test file with basic CRUD tests:Next Steps
Generate a hook
Add custom logic to your service
Add authentication
Secure your services with authentication
Services are automatically registered in
src/services/index.ts and available immediately after generation.