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数据库。无需账户。除非认领到Neon账户,否则数据库将在72小时后过期。
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