Validation
Validate your environment variables against a schema to prevent misconfigurations and ensure reliability.
Validation with Env-Sentinel
Env-Sentinel allows you to validate your .env
files against a schema to ensure type safety, presence of required variables, and correct formatting. Using schema-based validation reduces runtime errors and enforces consistency across environments.
Core Validators
Validator | Description | Example |
---|---|---|
string | Ensures the value is a string | APP_NAME=required|string |
number | Ensures the value is numeric | APP_PORT=required|number|min:1|max:65535 |
min | Minimum value or length | API_KEY=required|min:32 |
max | Maximum value or length | MAX_CONNECTIONS=optional|number|max:100 |
boolean | Must be true or false | DEBUG=optional|boolean |
secure | Sensitive value that should not be exposed | DB_PASSWORD=required|secure |
enum | Must match one of the allowed values | APP_ENV=required|enum:development,staging,production |
Example Schema
# Application Configuration APP_NAME=required|desc:"Application name displayed in logs and UI"|example:"MyAwesomeApp" APP_ENV=required|enum:development,staging,production|desc:"Application environment mode"|example:"production" APP_DEBUG=boolean|desc:"Enable debug mode with verbose logging"|default:"false" APP_URL=required|desc:"Base URL of the application"|example:"https://myapp.com" APP_PORT=number|min:1|max:65535|desc:"Port number for the application server"|default:"3000" # Database Configuration DB_CONNECTION=required|enum:mysql,postgresql,sqlite|desc:"Database driver to use"|example:"mysql" DB_HOST=required|desc:"Database server hostname or IP address"|example:"localhost" DB_PORT=required|number|min:1|max:65535|desc:"Database server port number"|example:"3306" DB_PASSWORD=required|secure|desc:"Database password (keep secure!)"
How It Works
- Generate a Schema (optional) – If you don't have a schema yet, run:
npx env-sentinel init
- Define a Schema – Specify the expected environment variables and rules.
- Run Validation – Compare your .env against the schema:
npx env-sentinel validate
- Review Results – Env-Sentinel reports errors, warnings, and notices.