env-check is a smart environment variable validator and manager from SphereOps that solves common problems with .env files in development teams and multi-environment deployments.
In many projects, especially in teams or multi-environment deployments (dev/stage/prod), managing .env files can be challenging:
- Missing or misconfigured environment variables cause silent failures
- Environment files are inconsistent across environments
- No validation of variable types or required values
- Difficulty in safely sharing sensitive environment variables with team members
- Uncertainty about which variables are actually used in the codebase
env-check solves these problems with a comprehensive set of features:
- Validate: Check environment variables against a schema for required values and correct types
- Compare: Find differences between environment files (e.g., dev vs. prod)
- Generate: Create schema files or templates from existing environment files
- Code Check: Identify unused or missing variables referenced in your code
- Security: Encrypt sensitive environment files for safe sharing with team members
- Format Support: Works with .env, JSON, and YAML formats
npm install -g env-checkThis will make the env-check command available globally in your terminal.
For system-wide installation on Linux (making it available to all users):
- Install the package globally first:
sudo npm install -g env-check- Create a symbolic link to make it available as a system utility:
sudo ln -s $(which env-check) /usr/local/bin/env-check- Ensure it's executable:
sudo chmod +x /usr/local/bin/env-checkYou can also use the tool without installing it:
npx env-checkCheck your .env file against a schema:
env-check validate --file .env --schema env.schema.jsonCheck if variables are actually used in your code:
env-check validate --file .env --code-checkFind differences between environment files:
env-check diff .env.dev .env.prodOutput as JSON:
env-check diff .env.dev .env.prod --output jsonGenerate a schema from your current .env file:
env-check init --type schema --file .envGenerate an .env.example template:
env-check init --type example --file .envEncrypt an environment file for safe sharing:
env-check encrypt .env --output .env.encryptedDecrypt an encrypted environment file:
env-check decrypt .env.encrypted --output .env.decryptedenv-check uses a JSON schema format to validate environment variables. Here's an example:
{
"PORT": {
"type": "number",
"required": true,
"description": "Port the server will listen on"
},
"API_KEY": {
"type": "string",
"required": true,
"sensitive": true
},
"DEBUG_MODE": {
"type": "boolean",
"required": false,
"default": "false"
}
}Supported types:
string: Regular string valuenumber: Numeric valueboolean: Boolean value (true,false,0,1,yes,no)url: Valid URLemail: Valid email addressipaddress: Valid IP address
-
Stop Fighting .env Files: No more debugging issues caused by missing or incorrectly configured environment variables.
-
Team Consistency: Ensure everyone on your team has the correct variables across all environments.
-
Onboarding Made Easy: New team members can get up and running quickly with correctly configured environments.
-
CI/CD Ready: Validate environment variables in your CI/CD pipeline before deployment.
-
Security First: Safely share sensitive credentials with team members using encryption.
-
Documentation Built-in: Schema files document what each variable is for and what format it should have.
-
Cleanup Unused Variables: Identify and remove environment variables that aren't used in your code.
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License - see the LICENSE file for details.
SphereOps specializes in building developer tools that make operations and DevOps workflows more efficient and error-free. # check-env