Framework Adapters
env-guard provides first-class integrations for popular frameworks. Each adapter provides separate client / server schemas and automatically applies the framework's public-variable prefix to client-side keys.
Available Adapters
| Adapter | Client prefix | Import |
|---|---|---|
createNextEnv | NEXT_PUBLIC_ | import { createNextEnv } from "@frauschert/env-guard" |
createViteEnv | VITE_ | import { createViteEnv } from "@frauschert/env-guard" |
createAstroEnv | PUBLIC_ | import { createAstroEnv } from "@frauschert/env-guard" |
createSvelteKitEnv | PUBLIC_ | import { createSvelteKitEnv } from "@frauschert/env-guard" |
createRemixEnv | (none) | import { createRemixEnv } from "@frauschert/env-guard" |
How They Work
- You define a
clientschema (public variables) and aserverschema (private variables). - The adapter automatically prefixes client-side keys with the framework's convention.
- Server-side keys are read without any prefix.
- Errors from both schemas are collected and reported together in a single batch.
Shared Options
All adapters accept an optional options object (same as createEnv, except prefix — which is set by the adapter):
ts
const env = createNextEnv({
client: {
/* ... */
},
server: {
/* ... */
},
options: {
envFiles: true,
onError: (errors) => console.error(errors),
},
});Return Shape
Each adapter returns an object with client and server properties:
ts
const env = createNextEnv({ client: { ... }, server: { ... } });
env.client.API_URL; // from NEXT_PUBLIC_API_URL
env.server.DATABASE_URL; // from DATABASE_URLSee the individual framework pages for complete examples: