Tuesday, December 9, 2025

thumbnail

Using Config Files for Environment Management

 ๐Ÿš€ What Is Environment-Based Configuration?

Environment management means having different configuration values (URLs, DB credentials, feature flags, secrets, logging levels, etc.) depending on where the app is running:

Development

Testing

Staging

Production

Configurations should not be hardcoded into the applicationinstead, they should be kept in environment-specific config files or environment variables.

๐Ÿงฉ Why Use Config Files?

Avoid hardcoding values

Makes the application easier to maintain and deploy.

Simplify multi-environment deployment

Just swap the config filenot the code.

Improve security

Secrets can be injected from secure sources (Vault, Key Vault, AWS Secrets Manager).

Support CI/CD pipelines

Environment-specific configs load automatically during deployments.

๐ŸŒ Common Environment Management Approaches

Most frameworks use multiple config files, named by environment.

๐Ÿงฑ 1. Environment Config in .NET

Files:

appsettings.json

appsettings.Development.json

appsettings.Staging.json

appsettings.Production.json

How it works

ASP.NET Core loads:

appsettings.json

Then overrides with appsettings.{Environment}.json

Set environment:

Windows

setx ASPNETCORE_ENVIRONMENT "Staging"

Linux

export ASPNETCORE_ENVIRONMENT=Staging

Example

appsettings.Development.json:

{

"Logging": {

"LogLevel": "Debug"

},

"ConnectionStrings": {

"DefaultConnection": "Server=localhost;Database=myapp_dev;"

}

}

appsettings.Production.json:

{

"Logging": {

"LogLevel": "Warning"

},

"ConnectionStrings": {

"DefaultConnection": "Server=prod-db;Database=myapp_prod;"

}

}

๐Ÿ— 2. Environment Config in Spring Boot

Files:

application.properties

application-dev.properties

application-prod.properties

Activate a profile

spring.profiles.active=dev

Or via CLI:

java -jar app.jar --spring.profiles.active=prod

Example

application-dev.properties:

server.port=8081

logging.level.root=DEBUG

app.url=http://localhost:8081

application-prod.properties:

server.port=80

logging.level.root=ERROR

app.url=https://api.company.com

๐ŸŸฉ 3. Environment Config in Node.js

Files:

.env

.env.development

.env.production

Using dotenv package

npm install dotenv

Load it:

require("dotenv").config();

Example .env.production

DB_HOST=prod-db.company.com

NODE_ENV=production

PORT=80

.env.development

DB_HOST=localhost

NODE_ENV=development

PORT=3000

๐Ÿงช 4. Environment Config in Frontend Apps (React, Angular, Vue)

React

.env.development

.env.production

Example:

REACT_APP_API_URL=https://api.dev.com

Angular

environment.ts

environment.prod.ts

๐Ÿ›ก 5. Security Considerations

Never commit secrets to config files

Use:

Environment variables

Vault services

Kubernetes Secrets

Store non-sensitive environment values in config files

(Example: app URLs, logging levels).

Inject secrets at runtime

CI/CD pipelines typically handle this.

⚙️ 6. Best Practices for Environment Config Files

Best Practice Explanation

Use multiple config files One for each environment

Keep defaults in a base config Environment files override

Do not duplicate values Only override changed values

Do not commit secrets Use secure vaults

Use environment variables to choose the environment Dynamically determine environment at startup

Make configuration strongly typed (e.g., .NET Options Pattern) Prevents mismatches and missing keys

๐Ÿ“ฆ 7. Example Project Structure (Generic)

config/

├── default.json

├── development.json

├── staging.json

└── production.json

src/

└── main application files

Use environment variables to choose the config:

export APP_ENV=production

๐Ÿช„ 8. How CI/CD Uses Environment Config

During deployment pipelines:

Select environment (dev/staging/prod)

Load corresponding config file

Inject secrets (Azure Key Vault, AWS Secrets Manager)

Build application

Deploy with environment config

This enables zero-code-change deployments.

Summary

Using config files for environment management allows you to:

Cleanly separate config from application logic

Maintain different settings for different environments

Support CI/CD processes

Improve security and maintainability

Reduce manual errors

Typical environment config structure:

Environment Example File

Development appsettings.Development.json, application-dev.properties, .env.development

Testing appsettings.Test.json, .env.test

Staging appsettings.Staging.json

Production appsettings.Production.json, .env.production

Learn Selenium with JAVA Training in Hyderabad

Read More

Reading Environment Variables in Selenium Tests

Using HashMap and ArrayList to Store Test Data

Parameterization in TestNG Using @DataProvider

Working with CSV Files in Java for Test Automation

Visit Our Quality Thought Institute in Hyderabad

Get Directions

Subscribe by Email

Follow Updates Articles from This Blog via Email

No Comments

About

Search This Blog

Powered by Blogger.

Blog Archive