@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 aconfig/ 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.jsonSchema 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 theNODE_ENV environment variable:
Custom Config Directory
You can specify a custom configuration directory using theNODE_CONFIG_DIR environment variable:
Configuration Merging
Configuration files are merged in the following order (later files override earlier ones):default.json{NODE_ENV}.json(e.g.,production.json)default-{instance}.json(for multi-instance deployments){NODE_ENV}-{instance}.jsonlocal.json(not committed to source control)local-{instance}.json
Advanced Features
Nested Configuration
Configuration values can be deeply nested: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: