Type-safe environment variable validation using Effect Schema
npm install @ayronforge/better-envTypesafe environment variables using Effect Schema.
Never deploy with invalid environment variables again. better-env validates all your env vars at startup, gives you full TypeScript autocompletion, and keeps server secrets out of client bundles — powered by the Effect ecosystem.
For schemas, helpers, prefix support, framework presets, composable envs, resolvers, and more — visit the documentation.
- Full type inference — env vars are fully typed from your schemas, no manual annotations needed
- Client / server separation — server-only vars throw at runtime if accessed on the client
- Eager validation — all errors collected and reported at once on startup
- Built-in schemas — booleans, ports, URLs, database URLs, JSON, enums, and more
- Secret manager resolvers — fetch secrets from AWS, GCP, Azure Key Vault, and 1Password
- Node.js 18+
- ESM only
- effect ^3.19.11
``bashnpm
npm install @ayronforge/better-env effect
Quick start
`ts
import {
createEnv,
requiredString,
port,
withDefault,
boolean,
postgresUrl,
redacted,
} from "@ayronforge/better-env";export const env = createEnv({
server: {
DATABASE_URL: postgresUrl,
API_SECRET: redacted(requiredString),
PORT: withDefault(port, 3000),
DEBUG: withDefault(boolean, false),
},
client: {
PUBLIC_API_URL: requiredString,
},
});
env.DATABASE_URL; // string — fully typed
env.API_SECRET; // string — redacted value auto-unwrapped
env.PORT; // number — transformed from string
`If any variable is missing or invalid,
createEnv() throws immediately with detailed errors:`
EnvValidationError: Invalid environment variables:
DATABASE_URL: Expected a valid PostgreSQL connection URL
API_SECRET: Expected a string with at least 1 character(s), actual ""
``This project is heavily inspired by T3 Env by T3 OSS. Thanks to the T3 team for their work and contributions to open source.