Course contentsShow
← Software Engineering
Lesson 737 of 1,93323. Configuration ManagementFree lesson

Environment-Specific Configuration Files

Managing separate config files per environment (dev, staging, prod) and loading the appropriate one at runtime.

Environment-Specific Configuration Files

What you'll learn: How to organize and load separate configuration files for each deployment environment so your application behaves correctly wherever it runs.

The Core Idea

Your application needs different settings in development, staging, and production—different database URLs, API endpoints, logging levels, and feature flags. Rather than changing values manually before each deployment (error-prone and dangerous), you create separate configuration files for each environment and teach your application to load the right one automatically based on where it's running.

Think of it like having different outfits for different occasions. You don't modify your work clothes every morning—you simply pick the right outfit from your closet based on where you're going.

How It Works

You typically organize files by naming convention:

  • config.dev.json or config.development.json
  • config.staging.json
  • config.prod.json or config.production.json

Your application reads an environment variable (like APP_ENV or NODE_ENV) at startup to determine which file to load. If APP_ENV=production, it loads config.prod.json. If APP_ENV=development, it loads config.dev.json.

This combines two concepts you've already learned: environment variables (to signal which environment you're in) and configuration files (to store the actual settings). The environment variable acts as a selector, while the files contain environment-specific values.

Benefits

  • Safety: No manual editing before deployment—fewer mistakes
  • Clarity: Each environment's settings are explicit and visible
  • Version control: Track configuration changes per environment over time
  • Testing: Developers can run with dev config while prod remains untouched

Key Takeaway: Environment-specific configuration files let you maintain separate, explicit settings for each deployment environment and load the correct one automatically at runtime, reducing errors and simplifying deployments.