๐ป .env Therapist - Auto-Check & Validation Script
Prevent .env disasters with this automated sanity checker
#!/usr/bin/env python3
# .env Therapist - Configuration Sanity Checker
# Save as check_env.py and run: python3 check_env.py
import os
import sys
def diagnose_env_problems():
"""Main diagnostic function for .env issues"""
# 1. Check for common .env file patterns
env_files = ['.env', '.env.local', '.env.production', '.env.staging']
found_files = []
for env_file in env_files:
if os.path.exists(env_file):
found_files.append(env_file)
print(f"โ
Found: {env_file}")
if not found_files:
print("โ No .env files found - are you missing configuration?")
return False
# 2. Check for sensitive patterns in .env files
sensitive_patterns = ['PASSWORD', 'SECRET', 'KEY', 'TOKEN', 'PRIVATE']
for env_file in found_files:
print(f"\n๐ Scanning {env_file} for issues...")
try:
with open(env_file, 'r') as f:
lines = f.readlines()
for i, line in enumerate(lines, 1):
line = line.strip()
# Skip empty lines and comments
if not line or line.startswith('#'):
continue
# Check for sensitive variables without proper naming
for pattern in sensitive_patterns:
if pattern in line.upper() and not line.startswith('#'):
print(f" โ ๏ธ Line {i}: Potential sensitive variable: {line.split('=')[0]}")
# Check for empty values
if '=' in line and line.endswith('='):
print(f" โ Line {i}: Empty value detected")
except Exception as e:
print(f" Error reading {env_file}: {e}")
# 3. Git safety check
if os.path.exists('.git'):
print("\n๐ Git repository detected")
print(" Tip: Add .env* to .gitignore if not already done")
return True
if __name__ == "__main__":
print("๐ง .env Therapist - Starting diagnosis...\n")
diagnose_env_problems()
print("\nโ
Diagnosis complete. Review warnings above.")
The Problem: Your Configuration Is a Hot Mess
Let's be honest: your team's approach to environment variables is what happens when you give developers the responsibility of state secrets without the training. You've got the .env.local that only works on Dave's machine because he added a secret variable three months ago and forgot to tell anyone. You've got the .env.staging that's actually just a copy of .env.production with 'localhost' swapped in, except for that one API key that's still pointing to production because who has time to check?
The absurdity reaches peak comedy when you realize your team has developed an elaborate ritual around these files. There's the 'whisper-and-point' method ('Hey, can you look at my screen but not read the values?'), the 'password-protected-ZIP-file' approach (which everyone just shares the password for anyway), and my personal favorite: the '17-different-versions-with-subtle-inconsistencies' strategy that guarantees something will break at 3 AM.
This isn't just annoyingโit's expensive. According to my completely made-up but probably accurate statistics, developers spend approximately 47% of their debugging time chasing environment variable ghosts. That's time that could be spent writing actual features, or at least scrolling through memes with a clear conscience.
The Solution: Passive-Aggressive Configuration Therapy
I built .env Therapist because sometimes what your configuration needs isn't another linter or validatorโit needs a gentle, judgmental intervention. This tool doesn't just check your files; it understands the emotional baggage your environment variables carry after years of neglect and inconsistency.
At its core, .env Therapist is brutally simple: it scans your .env files, compares them against a template (because yes, you should have templates), and points out everything that's wrong in the most passive-aggressive way possible. Think of it as that friend who says 'I notice you're still using the same password since 2012' with just enough concern to make you feel guilty.
But here's the secret: beneath the sarcastic exterior, this tool is actually useful. It catches real problems before they become production incidents. It enforces consistency across environments. And it does it all without requiring you to learn yet another configuration language or build system.
How to Use It: Your First Therapy Session
Getting started is easier than explaining to your manager why staging has been down for three hours. First, install it:
npm install -g env-file-therapist
# or
pip install env-file-therapist
Create a .env.template file that defines what variables should exist (without the actual sensitive values, pleaseโwe've learned that lesson):
# .env.template
API_KEY=your_key_here
DATABASE_URL=postgresql://user:password@host:port/db
DEBUG=false
Now run the therapist against your actual .env file:
env-therapist check --file .env --template .env.template
Here's a taste of what the actual code looks like when it's detecting issues:
def check_for_localhost_in_production(env_dict, filename):
"""Because apparently some people need this pointed out."""
if 'production' in filename and 'localhost' in str(env_dict.values()):
return [
"I notice you're using 'localhost' in production. "
"Would you like to talk about that?"
]
return []
Check out the full source code on GitHub to see all the lovingly crafted judgment.
Key Features: All the Ways It Judges You
- Template Comparison: Scans .env files and compares them against a template to find missing or extra variables. Because nothing says 'professional' like discovering your staging environment is missing half the required variables.
- Anti-Pattern Detection: Detects common sins like production keys in local files or placeholder values still in use. 'YOUR_API_KEY_HERE' is not a valid Stripe key, Karen.
- Therapeutic Feedback: Generates gentle, passive-aggressive suggestions that make you question your life choices. 'I see you have 127 environment variables. Have you considered that maybe, just maybe, your microservice isn't that micro?'
- Multi-Environment Support: Compares across your local, staging, and production files to find inconsistencies that will definitely, absolutely cause problems later.
- CI/CD Ready: Fails builds when things are wrong, because sometimes tough love is what you need.
Conclusion: Get Your Configuration Healthy
.env Therapist won't solve all your problems (you'll still have to actually fix the issues it finds), but it will save you from those late-night debugging sessions where you're questioning your career choices. It brings consistency to the chaos, sanity to the madness, and just enough sarcasm to make the medicine go down.
The best part? It's completely free and open source. No SaaS subscriptions, no feature gates, just pure, unadulterated configuration judgment. Try it out: https://github.com/BoopyCode/env-file-therapist
Your .env files have been suffering in silence for too long. Give them the therapy they deserve. And maybe, just maybe, you'll finally get that Docker container to work in production.
Quick Summary
- What: .env Therapist scans your environment files, compares them against templates, and passive-aggressively points out your configuration sins before they ruin your weekend.
๐ฌ Discussion
Add a Comment