{"_id":"@duanyijia/env-fill","name":"@duanyijia/env-fill","dist-tags":{"latest":"0.1.0"},"versions":{"0.1.0":{"name":"@duanyijia/env-fill","version":"0.1.0","description":"Zero-dependency missing-env-var detector with an in-browser form that writes values back to .env — so API keys never touch your coding agent's context.","main":"env-setup.js","types":"env-setup.d.ts","scripts":{"demo":"node demo/server.js"},"keywords":["env","dotenv","environment-variables","api-key","secrets","setup","onboarding","coding-agent"],"engines":{"node":">=16"},"repository":{"type":"git","url":"git+https://github.com/YijiaDuan/env-fill.git"},"author":{"name":"duanyijia1995","email":"duanyijia1995@gmail.com"},"license":"MIT","_id":"@duanyijia/env-fill@0.1.0","bugs":{"url":"https://github.com/YijiaDuan/env-fill/issues"},"homepage":"https://github.com/YijiaDuan/env-fill#readme","_nodeVersion":"22.22.2","_npmVersion":"10.9.7","dist":{"integrity":"sha512-KeOwDbAoCU/yq/3pOzK2TjcAsSdV+dq8D3mOTc6gkJDY+RBY9X45AUFpo71lqPbrVZo8gThvhdZFVpHsRLWOCA==","shasum":"898f3d97f94bb91587ea8475024bce3de2655f89","tarball":"https://registry.npmjs.org/@duanyijia/env-fill/-/env-fill-0.1.0.tgz","fileCount":5,"unpackedSize":14241,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEQCIFxhpYvy//+QY4WjZfEZc0A4NXKBjK8cgDpmqZqntJEzAiA7tAffkOByHX1DY86aehDTL/yw0yyVGsaWCGfzcayxdA=="}]},"_npmUser":{"name":"duanyijia","email":"duanyijia1995@gmail.com"},"directories":{},"maintainers":[{"name":"duanyijia","email":"duanyijia1995@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/env-fill_0.1.0_1779853112660_0.7941790780423248"},"_hasShrinkwrap":false}},"time":{"created":"2026-05-27T03:38:32.470Z","0.1.0":"2026-05-27T03:38:32.782Z","modified":"2026-05-27T03:38:33.023Z"},"maintainers":[{"name":"duanyijia","email":"duanyijia1995@gmail.com"}],"description":"Zero-dependency missing-env-var detector with an in-browser form that writes values back to .env — so API keys never touch your coding agent's context.","homepage":"https://github.com/YijiaDuan/env-fill#readme","keywords":["env","dotenv","environment-variables","api-key","secrets","setup","onboarding","coding-agent"],"repository":{"type":"git","url":"git+https://github.com/YijiaDuan/env-fill.git"},"author":{"name":"duanyijia1995","email":"duanyijia1995@gmail.com"},"bugs":{"url":"https://github.com/YijiaDuan/env-fill/issues"},"license":"MIT","readme":"# env-fill\n\n> Zero-dependency missing-env-var detector with an **in-browser form** that writes values back to `.env`.\n> Fill API keys right in your app's UI — they never touch your coding agent's chat context.\n>\n> 零依赖的「缺失环境变量检测器」，带一个**浏览器内填写表单**，把值写回 `.env`。\n> 直接在应用界面里填 API Key —— 密钥不进 coding agent 的对话上下文。\n\n## Why / 解决什么\n\nWhen you build apps with a coding agent, you constantly need to put API keys into env vars. You don't want the\nsecret in the agent's context, but opening `.env` to hunt for the right field every time is annoying. `env-fill`\ndetects which required vars are missing, redirects to a setup page, and lets you fill them in the browser — the\nvalue goes straight from browser to disk.\n\n用 coding agent 开发时常要往环境变量塞 API Key：既不想密钥进 agent 上下文，又不想每次翻 `.env` 找字段。\n`env-fill` 检测缺哪些必填变量、把页面请求引导到设置页、让你在浏览器填，值从浏览器直达磁盘。\n\n## Install / 安装\n\n```bash\nnpm install @duanyijia/env-fill\n# or, straight from GitHub:\nnpm install github:YijiaDuan/env-fill\n```\n\nZero dependencies. Node >= 16. Works with plain `http`, Express, or any Connect-style server.\n\n## Usage / 用法\n\n### Plain Node `http`\n\n```js\nconst http = require(\"http\");\nconst { createEnvSetup, loadEnvFiles } = require(\"@duanyijia/env-fill\");\n\nloadEnvFiles(); // read existing .env / .env.local into process.env\n\nconst envSetup = createEnvSetup({\n  vars: [\n    { key: \"OPENAI_API_KEY\", label: \"OpenAI API Key\", required: true, help: \"From platform.openai.com\" },\n    { key: \"BASE_URL\", label: \"API Base URL\", required: false, secret: false },\n  ],\n});\n\nhttp.createServer(async (req, res) => {\n  if (await envSetup.handle(req, res)) return; // serves /__setup + gates missing vars\n\n  // ...your real app...\n  res.end(\"hello\");\n}).listen(3000);\n```\n\n### Express\n\n```js\napp.use(envSetup.middleware);\n```\n\nThen start your app and open it. While a required var is missing, any page request redirects to `/__setup`.\nFill the form, hit save — values are written to `.env.local` **and** injected into the running process.\n\n启动后打开应用：只要有必填变量缺失，页面请求会跳到 `/__setup`。填完保存，值写入 `.env.local` 并注入当前进程。\n\n> 💡 Read env vars **at request time** (`process.env.X`) rather than once at module load, so values take effect\n> immediately without a restart.\n> 建议在**请求时**读 `process.env.X`，而不是模块加载时读一次，这样填完即时生效、无需重启。\n\n## API\n\n| Export | Description |\n|---|---|\n| `createEnvSetup(opts)` | Returns `{ handle, middleware, missing, ... }`. |\n| `loadEnvFiles(files?)` | Parse `.env` files into `process.env` (no overwrite). Defaults to `[\".env\", \".env.local\"]`. |\n| `writeEnvFile(file, updates)` | Merge `key=value` pairs into an env file, preserving other lines. |\n\n### `createEnvSetup` options\n\n| Option | Default | Description |\n|---|---|---|\n| `vars` | — | `[{ key, label, help, required, secret, placeholder }]` |\n| `envFile` | `.env.local` | File values are written to. |\n| `route` | `/__setup` | Route serving the form. |\n| `enabled` | `NODE_ENV !== \"production\"` | Disabled in production so the write endpoint never ships. |\n| `gate` | `true` | Redirect page requests to the form while required vars are missing. |\n\n## Security / 安全\n\n- **Disabled in production by default** — the disk-write endpoint won't ship to prod.\n- Add `.env*` to your `.gitignore` (this repo's `.gitignore` already does).\n- Secrets go browser → disk; they never enter the coding agent's context.\n\n## Demo\n\n```bash\nnpm run demo   # http://localhost:4321\n```\n\n## License\n\nMIT\n","readmeFilename":"README.md","_rev":"1-81b46f6f0fa6582d17293c5d48c3904c"}