What is a .env file?

A .env file (dotenv) is a plain text configuration file used to store environment variables for applications. It contains key-value pairs that define settings like database URLs, API keys, port numbers, and other configuration values that should remain separate from your code. The format originated from the Twelve-Factor App methodology, which recommends storing configuration in environment variables to keep sensitive data out of source code and make applications easily portable across different environments (development, staging, production).

Why validate .env files?

Environment variable files follow strict syntax rules: variable names must use uppercase letters, numbers, and underscores (starting with a letter or underscore), and each assignment must follow the KEY=value format. Invalid syntax, duplicate variables, or formatting errors can cause applications to fail silently or behave unpredictably. Validating .env files before deployment helps catch these issues early, prevents runtime errors, and ensures your configuration is correctly formatted.

Tool Description

The Dotenv Validator is a specialized tool for checking .env file syntax and structure. It validates that your environment variable file follows the correct format, identifies syntax errors with specific line numbers, detects duplicate variable declarations, and provides statistics about your configuration file. The validator helps developers ensure their .env files are properly formatted before using them in applications.

Features

  • Syntax Validation: Checks that all variable declarations follow the KEY=value format
  • Variable Name Checking: Ensures variable names use only uppercase letters, numbers, and underscores
  • Duplicate Detection: Identifies duplicate variable names and shows their location

Validation Rules

The validator enforces these .env file standards:

  • Variable names must start with a letter (A-Z) or underscore (_)
  • Variable names can only contain uppercase letters, numbers, and underscores
  • Each variable must follow the KEY=value format
  • No duplicate variable names are allowed
  • Comments (lines starting with #) and empty lines are ignored
  • Each variable assignment should be on its own line