config/default.json and can be customized per environment.
Supported Databases
The Feathers CLI supports the following databases:- MongoDB - Document database using the
@feathersjs/mongodbadapter - 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 aknexfile.ts that loads configuration from your app:
knexfile.ts
Environment Variables
Store database credentials in environment variables for security:config/custom-environment-variables.json
Connection Testing
Test your database connection:Best Practices
Use connection pooling
Use connection pooling
Configure appropriate pool sizes for your application’s load. Start with defaults and adjust based on monitoring.
Store credentials securely
Store credentials securely
Never commit database credentials to version control. Use environment variables and
custom-environment-variables.json.Use migrations for schema changes
Use migrations for schema changes
Always use migrations to manage database schema changes. This ensures consistency across environments.
Configure different databases per environment
Configure different databases per environment
Use separate databases for development, testing, and production. Configure them in environment-specific files.
Handle connection errors gracefully
Handle connection errors gracefully
Implement proper error handling for database connection failures and add retry logic where appropriate.