Skip to main content
The feathers generate connection command adds a new database connection to your application. This command is used to set up additional database connections beyond the initial one configured during app generation.

Usage

Alias: feathers g connection

Interactive Prompts

When you run this command, you’ll be prompted for:

Database Type

string
required
The type of database to connect toChoices:
  • sqlite - SQLite (file-based, no server required)
  • mongodb - MongoDB
  • postgresql - PostgreSQL
  • mysql - MySQL/MariaDB
  • mssql - Microsoft SQL Server
  • other - Other database via custom connection

Connection String

string
required
The connection string for the databaseDefault values by database type:
  • MongoDB: mongodb://127.0.0.1:27017/{name}
  • PostgreSQL: postgres://postgres:@localhost:5432/{name}
  • MySQL: mysql://root:@localhost:3306/{name}
  • SQLite: {name}.sqlite
  • MSSQL: mssql://root:password@localhost:1433/{name}

Connection Name

string
Optional name for the connection (used in configuration)If not provided, defaults to the database type (e.g., “mongodb”, “postgres”)

What Gets Generated

Running this command will:
1

Install database adapter

Installs the appropriate Feathers database adapter package:
  • @feathersjs/knex for SQL databases (PostgreSQL, MySQL, SQLite, MSSQL)
  • @feathersjs/mongodb for MongoDB
2

Install database driver

Installs the database-specific driver:
  • pg for PostgreSQL
  • mysql2 for MySQL
  • better-sqlite3 for SQLite
  • tedious for MSSQL
  • mongodb for MongoDB
3

Update configuration

Adds the connection string to your configuration files:
  • config/default.json - Default configuration
  • config/production.json - Production overrides
4

Create database client

Creates a new client file at src/{name}.ts that initializes the database connection
5

Register in application

Updates src/app.ts to configure and use the database connection

Example: Adding PostgreSQL

Generated files:
src/postgres.ts
Updated configuration:
config/default.json

Multiple Connections

You can run this command multiple times to add connections to different databases. Each connection will have its own configuration key and client file.

Environment Variables

Connection strings can use environment variables in production:
config/production.json
Never commit actual credentials to your repository. Use environment variables for sensitive connection information.

Next Steps

Generate a Service

Create a service that uses this database connection

Database Configuration

Learn more about database configuration options