Skip to main content
Feathers uses the powerful config module for application configuration. The @feathersjs/configuration package seamlessly integrates configuration management into your Feathers application.

Installation

Basic Setup

Configuration is typically set up in your main application file:

Configuration Files

The configuration module loads settings from JSON files in a config/ directory at your project root. Files are loaded based on the NODE_ENV environment variable.

Schema Validation

You can validate your configuration at application startup using a schema. This ensures your app fails fast with clear errors if configuration is invalid.
Then use the validator when configuring your app:
The validator runs as a setup hook and will throw detailed validation errors if configuration is invalid:

Common Configuration Patterns

Database Configuration

CORS Configuration

Authentication Configuration

Pagination Configuration

Environment Variables

Configuration values can be overridden using environment variables through the custom-environment-variables.json file.

Variable Formats

The __format key tells the config module how to parse the environment variable:

Usage

Environment variables always take precedence over configuration files, making them perfect for production deployments.

Accessing Configuration

Access configuration values anywhere in your application using app.get():

Using Configuration Without App

You can also use configuration outside of the Feathers application context:

Best Practices

Never commit sensitive information like API keys, database passwords, or authentication secrets to version control. Use environment variables for production secrets.

1. Use .gitignore

2. Document Required Variables

Create a .env.example file:

3. Validate Early

Always use schema validation to catch configuration errors before your app starts serving requests.

4. Use Typed Configuration

Define a TypeScript type for your configuration:

5. Keep Defaults Sensible

Your default.json should contain safe defaults for development. Production values should come from environment-specific files or environment variables.

Debugging Configuration

The configuration module uses the @feathersjs/commons debug module. Enable debug output:
This will show:
  • Which environment is being loaded
  • What configuration values are being set
  • The final merged configuration

Migration from Older Versions

If you’re upgrading from Feathers v4 or earlier:
  1. Configuration setup remains largely the same
  2. Schema validation is new in v5 - add it for better reliability
  3. The configuration module now uses setup hooks for validation
  4. Type safety has been improved with TypeScript