.env Config Generator
把环境变量写成可交付的 .env
按框架预设生成 .env、.env.example、docker-compose 与 JSON,校验必填、密钥强度、端口与布尔值;导入 .env / JSON 比对缺失与差异。全部在浏览器内完成,不上传密钥。
框架与环境
决定变量前缀密钥与配置卫生清单
交付前逐条过- 生产密钥只放平台的 Secret 管理,不提交到仓库;`.env` 只提交 `.env.example` 占位。
- 同一密钥被多个变量复用时轮换会漏改,导入本工具的现有 .env 比对可以发现这类“一钥多用”。
- 变量名全大写加下划线,前缀按子系统划分(`DB_`、`REDIS_`、`S3_`),避免跨服务撞名。
- 布尔值统一写 `true`/`false`,不要写 `1`/`yes`,不同语言解析行为不一致是线上事故高发点。
- 带空格或 `#` 的值必须加引号,否则 dotenv 会把后半段当注释截断。
- 数据库连接串里不要带明文密码;拆成 `HOST`/`USER`/`PASSWORD` 三段,方便平台单独注入。
- 每季度轮换一次长期密钥,轮换后同步更新 CI、容器编排与备份脚本三处,缺一处就会半夜报警。
- 导出到 Kubernetes / GitHub Actions / Terraform 前先确认目标格式的转义规则,YAML 的 `:` 与 `#` 尤其容易踩坑。
变量清单
0 个变量| 键名 | 值 | 类型 | 必填 |
|---|
先选框架,再点“载入该框架变量”,或直接从空表开始。
变量插值解析
0 行dotenv 支持 ${VAR} 与 ${VAR:-默认值}。这里一次性展开整份文件,找出未定义引用与循环引用,并对密钥值只给出掩码与指纹。
| 变量 | 引用 | 解析值 | 状态 | 指纹 |
|---|---|---|---|---|
| 点“解析引用”后显示 | ||||
指纹用于跨环境比对同一密钥是否一致:只对解析后的值计算,不可逆,也不会显示原文。
目标运行时兼容
同一份值,四个去处Docker env-file、systemd EnvironmentFile、Vercel、GitHub Actions 对引号、插值、换行与保留名称的处理各不相同,导出前先按目标运行时过一遍。
| 变量 | 结论 | 说明 |
|---|---|---|
| 生成变量后检查 | ||
尚未检查。
导入 .env / JSON 比对
只读解析输出格式对照
同一份变量八种去处| 格式 | 使用场景 | 注意 |
|---|---|---|
| .env | 本地开发与 dotenv 库 | 值含空格或 # 必须加引号 |
| .env.example | 仓库占位模板 | 只留键名与示例值,绝不提交真实密钥 |
| docker-compose | 本地容器编排 | 列表项写法,冒号后必须有空格 |
| Kubernetes Secret | 集群注入 | 值必须 base64,多行用块标量 |
| GitHub Actions | CI 变量 | 写进 env 段,敏感值走 Secrets 引用 |
| Terraform tfvars | 基础设施即代码 | HCL 字符串要转义引号与反斜杠 |
同一组变量导出到不同平台时,缩进、引号与转义规则都不同,复制粘贴前先在本工具里切换格式核对一遍。
生成结果
等待生成生成后在这里查看输出。
配置体检
0 条密钥强度与复用
未体检按字符集估算熵值,并检测占位符与同值复用。熵值只是下界:真实口令的分布远低于随机串。
| 变量 | 长度 | 熵(bit) | 等级 | 问题 |
|---|---|---|---|---|
| 点“体检当前密钥”后显示 | ||||
交付提醒
三条底线- .env 只保存在部署机与密钥管理服务里,提交到仓库的只有 .env.example。
- 生成的前端变量(NEXT_PUBLIC_、VITE_)会被打包进浏览器,不能放数据库口令。
- 更换环境时保留同名键,只改值;密钥轮换后要同时更新部署平台与本地文件。
How to Use
📖 What it does
A new project usually starts with configuration copied from an old project and half-remembered notes. Nobody knows which keys are required at handover, staging misses one variable, production ships with debug mode on, and the example file still contains a real secret.
This page turns the common framework variables into presets, lets you edit them as a table, and exports a full .env, a masked .env.example, a docker-compose block and JSON. Before exporting it checks key naming, duplicate keys, required values, port ranges, boolean spelling and secret strength.
It works on text only: nothing connects to your servers and nothing is written to disk. Importing an existing .env is a local diff that answers questions like “which key exists in production but not in the template”.
✨ Features
- Ten presets: Next.js, Vite, Node with Express, Django, Laravel, Spring Boot, Rails, Docker Compose, Cloudflare Workers and a blank custom set.
- Edit keys, values, types and required flags directly in the table, adding or removing rows as needed; types cover string, url, int, bool, enum, secret, email and host.
- Generate secrets in bulk: APP_KEY becomes base64 of 32 random bytes and every row marked as secret gets a fresh random string from crypto.getRandomValues.
- Five outputs: .env, .env.example with three masking strategies, docker-compose.yml, JSON and shell export statements.
- Ten validation families: key pattern, duplicate keys, required values, URL scheme, email shape, host without scheme, integers, ports from 1 to 65535, booleans, enum membership, secret length, placeholder words, low entropy, public prefixes carrying secrets, spaces needing quotes and debug mode in production.
- An A to D readiness grade with one line per deduction, so a failing configuration explains itself instead of just turning red.
- Import an existing .env and diff it: missing keys, extra keys, changed values and invalid line numbers, then fill the table from the import with one click.
- Export the variable list as CSV and copy or download .env, .env.example, docker-compose.yml, env.json and env.sh.
- Kubernetes Secret, GitHub Actions and Terraform tfvars outputs turn one variable set into cluster, CI and infrastructure code without retyping.
- Go (gin / echo) and Rust (axum / actix) presets cover HTTP_ADDR, RUST_LOG, pool sizes and the keys those stacks usually read.
- dotenv parsing now handles a BOM, CRLF, single and double quotes, escapes and multi-line values, and strips trailing comments only when the value is unquoted.
- Secret reuse detection warns when one value backs several variables, so a rotation cannot silently miss a copy.
- The import box accepts both .env files and JSON objects, reports JSON syntax errors explicitly, and uses one parser for diff and fill.
- Diff results are now a field-level table showing the current and imported value of every changed key, up to twelve rows.
- A secret strength check estimates entropy from the character set and adds length, placeholder and reuse rules, grading each secret from A to D and surfacing the weakest finding.
- An env.d.ts output turns the variable table into a TypeScript ProcessEnv declaration so a misspelled key fails at compile time.
- A reference check reports any ${VAR} placeholder whose key is missing from the table instead of letting it expand to an empty value.
- The secret check now validates platform formats for AWS, Stripe, GitHub, Slack, SendGrid and WeChat AppSecret prefixes and lengths.
- Naming and value lint now flags reserved variables, doubled or trailing underscores, surrounding whitespace, unquoted #, credentials inside connection strings and non-boolean booleans.
- Fixed a false negative: secret variables under NEXT_PUBLIC_ or VITE_ prefixes were excluded by the regex and never reported; they are now a hard error.
- A split export writes .env and .env.secrets in one action so the repository file and the secret file stay separate.
- Key lists can be grouped by name prefix such as DB_ or S3_, with a comment inserted at each boundary.
- Variable interpolation resolves ${VAR} and ${VAR:-default}, flags undefined and circular references, and shows secrets only as a mask plus an 8-character fingerprint.
- Runtime compatibility checks cover Docker env-file, systemd EnvironmentFile, Vercel and GitHub Actions, calling out differences in quoting, interpolation, newlines and reserved prefixes.
🚀 How to use it
- Pick a framework and a target environment, press Load preset, and the table fills with that framework’s common keys.
- Adjust the values for your project, press Generate secrets for the sensitive rows, and add a row when the preset is missing something.
- Press Generate config and read the grade first; fix short secrets, out-of-range ports and debug mode in production before exporting.
- Switch between the .env, .env.example, docker-compose, JSON and shell tabs and copy or download whichever files the deployment needs.
- To reconcile an existing configuration, paste that .env into the import box, press Diff, and decide which side wins for each conflicting value.
⚠️ Before you rely on it
- .env.example masks sensitive values by default; that masked file is the one that belongs in the repository.
- The diff parses text only. It does not expand variable references and does not understand multi-line values or newlines inside quotes.
- The docker-compose output contains only the environment block; volumes, networks and service definitions are yours to write.
- Anything prefixed NEXT_PUBLIC_ or VITE_ is bundled into the front end and visible to every visitor, so never put a secret there.
- Generated secrets are a starting point: move them into a secret manager or the platform’s encrypted variables instead of leaving them in a file.
- Variable names change between framework versions, so check the preset against the official documentation before relying on it.