.env.sample ((exclusive)) -
The .env.sample file (sometimes called .env.example or .env.dist) is a critical but often overlooked tool in modern development. While your .env file holds the "keys to the kingdom"—like database credentials and API tokens—the sample file acts as the blueprint for other developers to set up their own environments.
2. What Is .env.sample?
.env.sample (or .env.example) is a template file that shows what environment variables the application expects, without including sensitive or environment-specific values. It is committed to version control and serves as documentation. .env.sample
- Dotenvx (by dotenv org): Allows
.envencryption and CI/CD injection. envsubst: For generating sample files fromenv.jsonschemas.- TypeScript users: You can generate an
.env.samplefrom your Zod schema. Example:// env.schema.ts const EnvSchema = z.object( DATABASE_URL: z.string().url().default('postgresql://localhost/mydb'), PORT: z.coerce.number().default(3000) ); // Script extracts keys to .env.sample
URL for the primary API
Your Stripe secret key. Get it from https://dashboard.stripe.com/apikeys
Start with "sk_test_" for testing. DO NOT commit live keys.
STRIPE_SECRET_KEY=sk_test_your_test_key_here Dotenvx (by dotenv org): Allows
5. Advanced structure patterns
A. Grouped by concern
# ==================
# SERVER
# ==================
HOST=0.0.0.0
PORT=8080
6. Tooling around .env.sample
| Tool | Purpose |
|------|---------|
| dotenv (npm) | Load .env into process.env |
| envalid | Validate env vars against a schema |
| dotenv-vault | Manage sync of .env to .env.sample |
| direnv / autoenv | Auto-load .env in dev shell |
| check-env (CLI) | Compare .env vs .env.sample | URL for the primary API