Skip to main content
The @feathersjs/configuration package provides a small but powerful configuration module for Feathers applications. It uses the node-config library to manage environment-specific configuration files.

Installation

Basic Usage

Configuration files should be placed in a config/ directory at the root of your application:

Initialize Configuration

API

configuration

Initializes the configuration module and returns a function that can be used to configure a Feathers application.
Schema<any> | Validator
Optional schema or validator function to validate configuration on setup
(app?: Application) => any
A function that configures the application with loaded configuration values

Configuration Files

default.json

The base configuration that applies to all environments:

Environment-Specific Files

Override defaults for specific environments: production.json
development.json

Schema Validation

You can validate your configuration using a schema validator. This ensures your configuration is correct before the application starts.

Validation Errors

If validation fails, the setup hook will throw an error with detailed information:

Using Without an App

You can also use the configuration module directly without a Feathers app:

Environment Variables

The configuration module respects the NODE_ENV environment variable:

Custom Config Directory

You can specify a custom configuration directory using the NODE_CONFIG_DIR environment variable:

Configuration Merging

Configuration files are merged in the following order (later files override earlier ones):
  1. default.json
  2. {NODE_ENV}.json (e.g., production.json)
  3. default-{instance}.json (for multi-instance deployments)
  4. {NODE_ENV}-{instance}.json
  5. local.json (not committed to source control)
  6. local-{instance}.json

Advanced Features

Nested Configuration

Configuration values can be deeply nested:
Access nested values using dot notation:

Null Values

The configuration module preserves null values:

Debug Logging

The configuration module uses the @feathersjs/commons debug utility. Enable debug logging to see configuration details:
This will output:

Type Safety

For TypeScript users, you can type your configuration: