Skip to Content
FrontendSetupEnvironment Setup Management

Environment Setup Management

Overview

This setup is a flexible, multi-environment configuration management approach to handle different environment settings securely and efficiently.

Directory Structure

project/ └── environments/ ├── .env.dev # Development environment configurations ├── .env.staging # Staging environment configurations └── .env.prod # Production environment configurations ├── .env # Shared variables across all environments ├── .env.local # Local development specific configurations (NEVER committed) ├── .env.example # Template for local environment setup

The .env.local file should never be committed to version control. It contains sensitive or personal configurations.

The variables in .env.local should be sent to the secrets of the deployed app.

Configuration Files

1. .env

Contains variables common to all environments:

  • Shared API endpoints
  • Default feature flags
  • Common application settings

2. .env.local

  • Used for local development
  • The variables here should be sent to the secrets of the deployed app
  • Contains sensitive or personal configurations
  • NEVER committed to version control

3. .env.example

  • Template for .env.local
  • Includes variable names with placeholder values
  • Helps new developers understand required configurations

4. Environment-Specific Files

  • .env.dev: Development-specific variables
  • .env.staging: Staging environment configurations
  • .env.prod: Production environment settings

Best Practices

1. Gitignore

# Ignore local environment file environments/.env.local

2. Manage .env.example

  • Include all variable names
  • Use placeholder values
  • Add comments explaining variable purposes

3. Local Development

  1. Copy .env.example to .env.local
  2. Fill in your local configuration values
  3. Never commit .env.local

4. Verify that all required environment variables are set

Use the env validator script to ensure that all required environment variables are present across all environment files (.env.dev, .env.staging, .env.prod) and the global (.env).

Environment Variable Validator

Example Configuration

.env

APP_NAME=MyProject LOG_LEVEL=info API_BASE_URL=https://api.myproject.com

.env.dev

DEBUG_MODE=true DATABASE_URL=postgresql://localhost/devdb

.env.local

# Personal or sensitive configurations DATABASE_PASSWORD=my-secret-local-password API_KEY=my-personal-api-key

Security Considerations

  • Keep sensitive data out of version control
  • Use environment-specific configurations
  • Rotate credentials regularly
  • Limit access to production configurations
Last updated on