惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

博客园 - Franky
有赞技术团队
有赞技术团队
宝玉的分享
宝玉的分享
雷峰网
雷峰网
Hugging Face - Blog
Hugging Face - Blog
V
V2EX
大猫的无限游戏
大猫的无限游戏
博客园 - 司徒正美
D
Docker
T
The Blog of Author Tim Ferriss
罗磊的独立博客
博客园 - 叶小钗
酷 壳 – CoolShell
酷 壳 – CoolShell
Blog — PlanetScale
Blog — PlanetScale
月光博客
月光博客
J
Java Code Geeks
Jina AI
Jina AI
博客园 - 【当耐特】
C
Check Point Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
腾讯CDC
Last Week in AI
Last Week in AI
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
V
Visual Studio Blog

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
Your .env.example Is Lying to You, Here's How to Fix It
Odejobi Abiola Samuel · 2026-06-23 · via DEV Community
Cover image for Your .env.example Is Lying to You, Here's How to Fix It

Odejobi Abiola Samuel

Last month I cloned a project, copied .env.example to .env, and ran npm run dev. The app crashed with a confusing database error. Turns out the example file was missing DATABASE_URL — someone had added it to the actual code months ago but forgot to update the example 🤔. I spent close to 45 minutes digging through source to find every env var the app needed.

This isn't a one-off. It can happens in every project that maintains .env.example by hand.

The problem

.env.example is documentation, and like all documentation, it drifts. Here's what goes wrong:

  • People add env vars and forget to update the example. This is the most common one. You need a new API key, so you add STRIPE_SECRET_KEY to your code and your actual .env. The example never gets touched.
  • People remove env vars and leave them in the example. New devs waste time setting up vars that aren't even used anymore.
  • Comments are minimal or nonexistent. A bare key like SMTP_HOST= tells you nothing. Is it a URL? An IP? A hostname? Good luck guessing.
  • No one knows what's optional vs required. New team members don't know if they can start without setting SENTRY_DSN or if the app will crash.

The manual workflow is: add a var to code → (hopefully) remember to add it to .env.example → (hopefully) write a comment. That's three places to update. It fails constantly.

The fix: generate it from your schema

If you define your env vars in a schema file, you can generate .env.example from that file. The schema is the source of truth, so the example can never drift.

Here's what I do with CtroEnv (but the principle applies to any schema-based approach):

// src/env.ts
import { defineEnv, string, number, pick } from "@ctroenv/core";

export const env = defineEnv({
  DATABASE_URL: string().url().describe("Full PostgreSQL connection string"),
  PORT: number().port().default(3000).describe("HTTP server port"),
  NODE_ENV: pick(["dev", "prod"] as const).describe("Runtime environment"),
  SENTRY_DSN: string()
    .optional()
    .describe("Sentry DSN for error tracking (optional)"),
  SMTP_HOST: string().describe("SMTP server hostname"),
  SMTP_PORT: number().port().default(587).describe("SMTP server port"),
});

Then run:

npx @ctroenv/cli generate

The output writes to .env.example automatically:

# DATABASE_URL (required)
# Full PostgreSQL connection string
DATABASE_URL=

# PORT (optional, defaults to 3000)
# HTTP server port
PORT=3000

# NODE_ENV (required)
# Runtime environment
# Allowed values: dev, prod
NODE_ENV=

# SENTRY_DSN (optional)
# Sentry DSN for error tracking (optional)
SENTRY_DSN=

# SMTP_HOST (required)
# SMTP server hostname
SMTP_HOST=

# SMTP_PORT (optional, defaults to 587)
# SMTP server port
SMTP_PORT=587

Compare this to the manual version that probably exists in your project right now:

DATABASE_URL=
PORT=3000
NODE_ENV=dev
SENTRY_DSN=
SMTP_HOST=
SMTP_PORT=587

The generated version tells you:

  • What each var is for (the .describe() text becomes a comment)
  • Whether it's required or optional
  • What the allowed values are (for pick validators)
  • What the default is

How it stays in sync

When you add a new env var, you add it to the schema. That's one place. The .env.example gets regenerated from the schema. It's impossible for them to disagree because the schema is the only thing you edit.

When you remove a var, it's also one edit. Next time someone runs npx ctroenv generate, the old var doesn't appear. No stale keys.

Bonus: this helps onboarding

A new developer cloning your repo can run:

npx @ctroenv/cli check

This compares their current .env against the schema and tells them exactly what's missing or wrong. No more "I think I set everything but it's still crashing."

Bonus: ENVIRONMENT.md generation

The same schema can generate full documentation:

npx @ctroenv/cli docs --format markdown

This produces an ENVIRONMENT.md file with a table of every env var, its type, whether it's required, its default, and its description. Stick it in your repo and link to it from your README.

What about other tools?

If you're using Zod, you can parse env vars with it, but generating .env.example from Zod schemas isn't built in. You'd need to write your own code to extract descriptions and defaults from Zod's ._def.

envalid has envalid.cleanEnv but no CLI-based generation. Same deal — you'd need a custom script.

t3-env doesn't support generation either.

That's actually what pushed me toward CtroEnv — I wanted npx ctroenv generate to just work.

Practical advice

  1. Stop editing .env.example directly. Even if you don't switch tools, make it a rule: edit the schema, regenerate the example.
  2. Run generation as a pre-commit hook. Catch drift before it hits the repo.
  3. Add descriptions. Future you will thank present you when you're debugging a production issue and need to remember what STRIPE_WEBHOOK_SECRET is for.
  4. Run check in CI. Fail the build if someone's .env doesn't match the schema.

Your .env.example file should be the first thing a new developer sees when they clone your repo. Make sure it's telling the truth.