better-env

作者: neondatabase

為代理和人類提供更好的環境變數管理,具備完整型別安全、基於命令列的遠端環境同步,以及環境驗證功能。…

npx skills add https://github.com/neondatabase/better-env --skill better-env

Work With better-env In A Repo

Type-safe environment config modules

Follow this best practice to manage environment variables in TypeScript applications with full type safety and clear server/public boundaries.

better-env exports configSchema to define typed env modules and recommends placing them in feature-level config.ts files (for example src/lib/auth/config.ts and src/lib/database/config.ts).

Learn more:

  • references/config-schema.md

Validate existence of all env variables in the current environment

Run env validation early so missing or invalid values fail fast before dev, build, or deploy steps.

better-env validate --environment <name> loads .env* files with Next.js semantics, discovers src/lib/*/config.ts modules, and checks every declared variable from your configSchema modules.

If your dotenv files intentionally include keys that are not referenced by config modules, add per-env suppressions in better-env.ts:

environments.<env>.ignoreUnused: string[]

These suppress only the selected local environment during validate. Adapter defaults are merged in automatically; for Vercel, VERCEL_OIDC_TOKEN is ignored by default in development, preview, and production.

Learn more:

  • references/env-validation.md

Configure runtime syncing between local files and hosted providers

Use runtime configuration to keep local dotenv targets aligned with provider environments while preserving safe defaults.

Create better-env.ts with defineBetterEnv(...) and an adapter (vercelAdapter, netlifyAdapter, railwayAdapter, or cloudflareAdapter).

For a standard Vercel setup, prefer the minimal config:

export default defineBetterEnv({ adapter: vercelAdapter() });

Do not add an environments block when it only duplicates adapter defaults. Add environments only when you intentionally need custom mappings, custom env files, or per-environment ignoreUnused behavior.

Learn more:

  • references/config.md
  • references/runtime.md

Use the CLI for day-to-day environment operations

The CLI gives a consistent workflow for initialization, sync, validation, and remote variable management, which is great for local development and CI automation.

Choose the command runner to match the repo:

  • Use npx in npm/pnpm-based repos (for example lockfiles like package-lock.json or pnpm-lock.yaml and scripts run via npm/pnpm).
  • Use bunx in Bun-based repos (for example bun.lock and scripts run via bun).
  • Keep commands aligned with the project's existing package manager/runtime conventions; do not mix runners unless the repo already does.

Recommended flow in a repo:

  1. Run better-env init once to verify adapter prerequisites.
  2. Run better-env pull --environment <name> to sync local env files.
  3. Run better-env validate --environment <name> before app startup/build.
  4. Use add, upsert, update, delete, and load for remote env changes.

Choose command behavior intentionally:

  • upsert for idempotent automation and scripts
  • add when duplicate keys should fail
  • update when missing keys should fail
  • delete to remove remote keys
  • load for batch updates from dotenv files

Learn more:

  • references/cli.md
  • references/vercel-adapter.md

來自 neondatabase 的更多技能

claimable-postgres
neondatabase
即時 Postgres 資料庫,適用於本地開發、展示、原型設計與測試環境。無需註冊帳號。資料庫在 72 小時後到期,除非認領至 Neon 帳號。
official
neon-postgres-branches
neondatabase
此技能的成果應為已建立的 Neon 分支(若無法建立,則提供明確且可執行的下一步)。選擇正確的分支類型,然後透過 MCP 或 CLI 執行分支建立。
official
neon-postgres-egress-optimizer
neondatabase
引導使用者診斷並修復應用端查詢模式,這些模式會導致從其 Postgres 資料庫傳輸過多資料(出口流量)。大多數高額出口帳單來自應用程式擷取超出實際使用的資料。
official
plugin-manager
neondatabase
管理此儲存庫在 Cursor 和 Claude Code 中的插件結構與配置。在建立、更新或審查插件資料夾時使用…
official
skill-creator
neondatabase
建立有效技能的指南。當使用者想要建立新技能(或更新現有技能)以擴展 Claude 的功能時,應使用此技能。
official
add-neon-docs
neondatabase
當使用者要求新增關於Neon的文件、文檔、參考資料或安裝文件時,使用此技能。新增Neon最佳實踐參考連結…
official
neon-auth
neondatabase
為你的應用程式設定 Neon Auth。配置驗證、建立驗證路由,並生成 UI 元件。在為 Next.js 加入驗證功能時使用,…
official
neon-drizzle
neondatabase
建立一個功能完整的 Drizzle ORM 環境,並搭配已配置的 Neon 資料庫。安裝相依套件、配置資料庫憑證、設定連線…
official