Prompt
Define a clear, hierarchical structure for application configurations with descriptive naming and proper organization. Avoid hardcoded values, use named constants for magic numbers, and ensure configuration is loaded only once at startup and passed through the application rather than loaded at arbitrary points.
Key practices:
- Use named constants instead of magic values:
// Avoid const deadline = Date.now() + 1000; // Better const PROCESS_TERMINATION_TIMEOUT_MS = 1000; const deadline = Date.now() + PROCESS_TERMINATION_TIMEOUT_MS; - Organize configurations hierarchically by functionality:
// Avoid output: { maxBytes: 12410, maxLines: 256 } // Better tools: { shell: { maxBytes: 12410, maxLines: 256 } } - Externalize hardcoded values:
// Avoid client_id: "Iv1.b507a08c87ecfe98" // Better client_id: process.env.GITHUB_CLIENT_ID || config.github.clientId - Load configuration once and thread it through:
// Avoid function someFunction() { const config = loadConfig(); // Loading config at arbitrary points // ... } // Better function someFunction(config) { // Config passed as parameter // ... } - Provide sensible defaults when configuration is missing:
// Avoid const providersConfig = config.providers; // Could be undefined // Better const providersConfig = config.providers ?? defaultProviders;
Following these practices makes configurations more maintainable, testable, and prevents unpredictable behavior in long-running applications when configurations change during execution.