Skip to main content

Overview

The feathers 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

Or using the shorthand:

Options

string
The name of the service. This will be used for class names, file names, and variable names.
Validation: Cannot be empty or “authentication”
string
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”
string
The service type/database adapter to use.
Choices:
  • knex - SQL databases (PostgreSQL, MySQL, SQLite, MSSQL)
  • mongodb - MongoDB database
  • custom - Custom service without database
Note: SQL and MongoDB options are only available if you have configured the respective database connection.

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
Note: SQL and MongoDB options are disabled if the connection is not configured.

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
Schemas allow you to type, validate, secure, and populate data.

Generated Files

For a service named “messages” with MongoDB and TypeBox:

With Nested Paths

For path api/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:
string
Original input name (e.g., “UserMessage”)
string
Camel case starting with lowercase (e.g., “userMessage”)
string
Camel case starting with uppercase (e.g., “UserMessage”)
string
Class name with “Service” suffix (e.g., “UserMessageService”)
string
Kebab case for files (e.g., “user-message”)
string
The last element of the path (e.g., “messages”)
string
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
Generates a service using @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:
  1. Adds authenticate('jwt') hook to all methods
  2. Restricts access to authenticated users only
  3. Populates user information in the hook context

Schema Validation

  • 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.