Skip to main content
Feathers supports multiple database adapters through its unified configuration system. Database configuration is stored in config/default.json and can be customized per environment.

Supported Databases

The Feathers CLI supports the following databases:
  • MongoDB - Document database using the @feathersjs/mongodb adapter
  • PostgreSQL - Relational database using Knex adapter
  • MySQL/MariaDB - Relational database using Knex adapter
  • SQLite - File-based relational database using Knex adapter
  • Microsoft SQL Server - Enterprise relational database using Knex adapter

MongoDB Configuration

MongoDB uses a connection string format for configuration.
string
MongoDB connection string.Format: mongodb://[username:password@]host[:port]/database[?options]Default: mongodb://127.0.0.1:27017/[app-name]

MongoDB Connection Example

config/default.json

MongoDB with Authentication

config/default.json

MongoDB Service Implementation

The CLI generates a MongoDB connection file:
src/mongodb.ts

SQL Databases (Knex)

SQL databases (PostgreSQL, MySQL, SQLite, MSSQL) use Knex as the query builder. The configuration varies slightly by database type.

PostgreSQL Configuration

object
PostgreSQL database configuration.

Connection Object Format

string
Database host address.
number
Database port number.
string
Database username.
string
Database password.
string
Database name.

MySQL Configuration

object
MySQL/MariaDB database configuration.

SQLite Configuration

object
SQLite database configuration.

Microsoft SQL Server Configuration

object
Microsoft SQL Server database configuration.

Configuration Examples

Knex Service Implementation

For SQL databases, the CLI generates a Knex connection file:
src/postgresql.ts

Migrations

When using Knex (SQL databases), the CLI sets up migration support:

Running Migrations

Migration Configuration

The CLI generates a knexfile.ts that loads configuration from your app:
knexfile.ts

Environment Variables

Store database credentials in environment variables for security:
config/custom-environment-variables.json
Then set the environment variable:

Connection Testing

Test your database connection:

Best Practices

Configure appropriate pool sizes for your application’s load. Start with defaults and adjust based on monitoring.
Never commit database credentials to version control. Use environment variables and custom-environment-variables.json.
Always use migrations to manage database schema changes. This ensures consistency across environments.
Use separate databases for development, testing, and production. Configure them in environment-specific files.
Implement proper error handling for database connection failures and add retry logic where appropriate.