π§© env-checkup validate
The validate command verifies that all your .env files match the definitions in your .env.schema.json.
It ensures that every required environment variable exists, has the correct type, and that no unwanted or missing values cause runtime issues.
π§© Usageβ
Run the following command inside your project root:
npx env-checkup validate
π§ What It Doesβ
When executed, Env Checkup will:
- Load your configuration from
envcheckup.config.json(if available). - Discover all
.envfiles recursively (e.g.,.env,.env.local,.env.example). - Load your
.env.schema.jsonfor expected variables and types. - Compare each
.envfileβs values with the schema. - Report missing or invalid variables, and success for valid ones.
π¬ Example Outputβ
$ npx env-checkup validate
π Checking environment files...
β
PORT = 3000
β
DATABASE_URL = postgres://localhost:5432/mydb
β οΈ Missing variable: JWT_SECRET
β Invalid type: DEBUG (expected boolean, got string)
Summary:
3/5 variables valid
2 issues found
π Example .env Fileβ
PORT=3000
DATABASE_URL=postgres://localhost/mydb
DEBUG=true
π Example .env.schema.jsonβ
{
"PORT": "number",
"DATABASE_URL": "string",
"JWT_SECRET": "string",
"DEBUG": "boolean"
}
Env Checkup compares these and immediately points out any missing or mismatched variables.
βοΈ Optionsβ
| Flag | Description | Example |
|---|---|---|
--schema <path> | Specify a custom schema file path | env-checkup validate --schema ./config/env.schema.json |
--dir <path> | Specify directory to search for .env files | env-checkup validate --dir ./envs |
--strict | Fail the command (non-zero exit) if any variable is missing or invalid | env-checkup validate --strict |
--ignore <vars> | Comma-separated variables to ignore during validation | env-checkup validate --ignore NODE_ENV,DEBUG |
--debug | Show detailed output (loaded config, found files, and schema path) | env-checkup validate --debug |
π§© Example Commandsβ
Validate using the default schema:β
npx env-checkup validate
Validate using a custom schema:β
npx env-checkup validate --schema ./config/env.schema.json
Validate files in a specific directory:β
npx env-checkup validate --dir ./config
Run in strict mode (useful for CI/CD):β
npx env-checkup validate --strict
If any issues are found, the process exits with a non-zero status code, which is perfect for automated pipelines.
Ignore specific variables:β
npx env-checkup validate --ignore NODE_ENV,DEBUG
π§ Example CI/CD Integrationβ
To ensure your environment is valid before deploying, add Env Checkup to your CI pipeline.
GitHub Actions example:
- name: Validate Environment Variables
run: npx env-checkup validate --strict
If validation fails, the workflow stops immediately β preventing bad configurations from being deployed.
π§© Example Project Structureβ
my-app/
β£ .env
β£ .env.local
β£ .env.schema.json
β£ envcheckup.config.json
β£ package.json
β src/
β index.ts
π§Ύ Example npm Scriptβ
You can simplify validation for your team by adding a script to package.json:
"scripts": {
"env:validate": "env-checkup validate --strict"
}
Then run:
npm run env:validate
π§° Debug Modeβ
Run in debug mode to inspect configuration and file discovery:
npx env-checkup validate --debug
Output example:
Loaded config: envcheckup.config.json
Schema path: ./.env.schema.json
Discovered files: [".env", ".env.local"]
Validating...
β
PORT = 3000
β οΈ Missing variable: JWT_SECRET
π§© Summaryβ
| Command | Description |
|---|---|
npx env-checkup validate | Validate .env files using schema |
--schema <path> | Use a custom schema path |
--dir <path> | Specify directory to search |
--strict | Fail build if any variable is missing |
--ignore <vars> | Skip validation for listed variables |
--debug | Show detailed validation process |
π Recommended Workflowβ
# Step 1 β Create schema file
npx env-checkup init
# Step 2 β Validate .env files
npx env-checkup validate
# Step 3 β Enforce strict mode in CI/CD
npx env-checkup validate --strict
β
Pro Tip:
Always commit .env.schema.json and envcheckup.config.json to version control β this keeps your environment setup consistent across all team members and deployments.