← Workflows

阅读中文版本

Environment File Setup Workflow

Create and validate a .env file for local development with required variables and safety checks to prevent secrets from being committed.

beginner~10 minenvironmentconfigurationworkflow

Objective

Set up a local environment configuration file with all required variables for development.

Environment

  • A project that uses environment variables for configuration
  • A .env.example template file documenting required variables
  • Git repository with .gitignore

Steps

1. Copy template

Copy .env.example to .env to create a local configuration file.

Expected state: A .env file exists with placeholder values.

2. Fill in values

Replace each placeholder with the appropriate local value for your development environment.

Expected state: All placeholders are replaced with real values.

3. Verify .gitignore

Confirm that .env is in .gitignore to prevent committing secrets.

Expected state: The .env file is excluded from version control.

4. Validate variables

Run the project startup command and verify that all required variables are recognized.

Expected state: The application starts without environment variable errors.

Decision points

What if a variable is missing from the template?

  • Add it to .env.example first
  • Add it only to .env

Add to .env.example first so teammates know it is required; then add to your local .env.

Expected outcome

A local .env file is configured with all required variables and is protected from accidental commits.

Verification

Run git status and confirm .env is not tracked; start the application and confirm no missing variable errors.

Cleanup

Never commit the .env file; if accidentally staged, unstage it immediately.

Never commit secrets

The .env file must always be in .gitignore. Use .env.example to document required variables without actual values.

cp .env.example .env
# Edit .env with your local values
grep ".env" .gitignore

Implementation Notes

  1. Copy template — Copy .env.example to .env to create a local configuration file. Expected state: A .env file exists with placeholder values.

  2. Fill in values — Replace each placeholder with the appropriate local value for your development environment. Expected state: All placeholders are replaced with real values.

  3. Verify .gitignore — Confirm that .env is in .gitignore to prevent committing secrets. Expected state: The .env file is excluded from version control.

  4. Validate variables — Run the project startup command and verify that all required variables are recognized. Expected state: The application starts without environment variable errors.

Common Pitfalls

  • What if a variable is missing from the template? Options: Add it to .env.example first / Add it only to .env. Recommendation: Add to .env.example first so teammates know it is required; then add to your local .env.