https://github.com/t3-oss/t3-env.git
Deploying your app with invalid environment variables is a hassle. This package helps you to avoid that.
For full documentation, see https://env.t3.gg
[!NOTE]
> This is an ESM only package that requires a tsconfig with a module resolution that can read package.json#exports (NodeNextif transpiling withtsc,Bundlerif using a bundler).
# npm
npm i @t3-oss/env-nuxt
# pnpm
pnpm add @t3-oss/env-nuxt
# bun
bun add @t3-oss/env-nuxt
# deno
deno add jsr:@t3-oss/env-nuxt
[!NOTE]
> You may use any Standard Schema compliant validator of your choice. This example uses Zod.
See the documentation for more details.
This package supports the full power of Zod/Valibot etc, meaning you can use transforms and default values.
// src/env.mjs
import { createEnv } from "@t3-oss/env-nextjs"; // or core package
import { z } from "zod";
export const env = createEnv({
/*
* Serverside Environment variables, not available on the client.
* Will throw if you access these variables on the client.
*/
server: {
DATABASE_URL: z.url(),
OPEN_AI_API_KEY: z.string().min(1),
},
/*
* Environment variables available on the client (and server).
*
* ๐ก You'll get type errors if these are not prefixed with NEXT_PUBLIC_.
*/
client: {
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY: z.string().min(1),
},
/*
* Due to how Next.js bundles environment variables on Edge and Client,
* we need to manually destructure them to make sure all are included in bundle.
*
* ๐ก You'll get type errors if not all variables from `server` & `client` are included here.
*/
runtimeEnv: {
DATABASE_URL: process.env.DATABASE_URL,
OPEN_AI_API_KEY: process.env.OPEN_AI_API_KEY,
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY:
process.env.NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY,
},
});
// src/app/hello/route.ts
import { env } from "../env.mjs";
export const GET = (req: Request) => {
const DATABASE_URL = env.DATABASE_URL;
// use it...
};
This project uses Bun as its package manager. To install:
# Linux & macOS
curl -fsSL https://bun.sh/install | bash
# Windows
powershell -c "irm bun.sh/install.ps1 | iex"
To get started, clone the repo:
git clone https://github.com/t3-oss/t3-env.git
It is recommended to use VSCode (or a fork like Cursor or Windsurf) with the recommended extensions installed.
Then, install the project dependencies:
cd t3-env
bun i
Checkout a feature branch for the change you're about to make:
git checkout <branch_name>
Implement your changes, then submit a Pull Request describing your changes.
bun run dev. This will recompile the necessary packages whenever you make changes.bun changeset to ensure your changes trigger a release with appropriate changelog.bun lint (bun lint:fix to fix auto-fixable issues)bun run test. Alternatively, you can use the test explorer in VSCode to target individual tests.Closes #123 in the description).@juliusmarminge to bump the issue.
MIT License ยฉ 2025 Julius Marminge