KrakenJS environment configuration for repeatable development setups
0 reputation · 03 Jul 2026, 14:39 UTC
0 reputation · 03 Jul 2026, 14:39 UTC
KrakenJS relies on a configuration-driven architecture using the config package to manage environment-specific settings. The framework supports default.json and environment-specific overrides such as development.json and production.json, but maintaining parity across diverse local development environments remains difficult when secrets or machine-specific paths are required.
Ensuring a repeatable development environment requires balancing committed configuration files with dynamic environment variables without introducing complex nesting that complicates debugging.
What is the recommended pattern for integrating environment variables into KrakenJS configuration files to ensure repeatability across development environments? Which approach best prevents configuration drift when overriding default.json values using external environment variables?
Use config/custom-environment-variables.json to declaratively map configuration keys to environment variable names, then load per-machine values from a gitignored .env file via dotenv before the config package initializes. This keeps the mapping version-controlled while secrets and machine-specific paths stay out of git.
The config package (used by KrakenJS) reads custom-environment-variables.json at require time and overlays any matching process.env values on top of default.json, development.json, and production.json. Because the mapping itself is committed, every developer and CI environment applies the same override structure — only the actual values differ per machine.
config/custom-environment-variables.json:{
"database": {
"host": "DB_HOST",
"password": "DB_PASSWORD"
},
"service": {
"apiKey": "SERVICE_API_KEY"
}
}.env in the project root with local values:DB_HOST=localhost
DB_PASSWORD=dev-only-secret
SERVICE_API_KEY=local-dev-keyserver.js):require('dotenv').config();
const config = require('config');
// config.get('database.host') now returns 'localhost'default.json and development.json with safe, non-secret defaults. Commit custom-environment-variables.json. Never commit .env.npm ls config to confirm the config package version (mapping file support exists since v1.x).default.json ("testKey": "default"), map it in custom-environment-variables.json ({"testKey": "TEST_VAR"}), set TEST_VAR=override in .env, start the app, and log config.get('testKey') to confirm the override works.process.env.TEST_VAR right after dotenv.config() and before require('config') to verify load order.config versions expect flat keys with dot notation (e.g., "database.host": "DB_HOST") instead of nested objects. Verify your version's syntax if overrides don't apply.config package behavior; no framework-specific differences exist for this pattern.Missing diagnostic detail: What config package version does your project currently resolve to? Run npm ls config and share the version if override behavior differs from the steps above.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.