config/ directory and loaded using the @feathersjs/configuration package. Configuration files are loaded based on the NODE_ENV environment variable.
Configuration Files
Feathers applications use the following configuration structure:config/default.json- Default configuration for all environmentsconfig/production.json- Production-specific overridesconfig/test.json- Test environment configurationconfig/custom-environment-variables.json- Maps environment variables to configuration
Configuration Schema
When generating a new application with schemas enabled, Feathers creates a configuration schema that validates your application settings.Core Settings
The hostname the server should bind to.Default:
localhostEnvironment Variable: HOSTNAMEThe port number the server should listen on.Default:
3030Environment Variable: PORTThe path to the public directory for serving static files.Default:
./public/An array of allowed CORS origins. Used for cross-origin requests.Default:
['http://localhost:3030']Pagination Settings
Default pagination settings for database queries.
Example Configuration
Usage
The configuration is automatically loaded and applied to your application:src/app.ts
Validation
When using schemas, configuration is validated during application setup. Invalid configuration will throw an error before the application starts:src/app.ts
Environment Variables
Map environment variables to configuration values usingconfig/custom-environment-variables.json:
__format option converts the environment variable to the specified type. Supported formats include:
number- Parse as numberjson- Parse as JSONboolean- Parse as boolean
Best Practices
Use environment-specific files
Use environment-specific files
Keep environment-specific settings in separate files (
production.json, staging.json, etc.) rather than in default.json.Never commit secrets
Never commit secrets
Store sensitive values like API keys and secrets in environment variables, not in configuration files. Use
custom-environment-variables.json to map them.Validate your configuration
Validate your configuration
Always use configuration schemas to catch errors early and ensure your application has valid settings.
Document custom settings
Document custom settings
Add comments to your configuration schema to document what each setting does and its valid values.