@sutterhill/env
v1.1.0
Published
 [](https://jsr.io/@sutterhill/env) [](https://jsr.io/@sutterhill/env) [![Socket Bad
Downloads
20
Readme
Typesafe Envs made Simple
This is the framework agnostic core package of env.
Installation
# npm
npm i @sutterhill/env
# pnpm
pnpm add @sutterhill/env
# bun
bun add @sutterhill/env
# deno
deno add jsr:@sutterhill/envUsage
[!NOTE]
You may use any Standard Schema compliant validator of your choice. This example uses Zod
// src/env.ts
import { createEnv } from "@sutterhill/env";
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.string().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 PUBLIC_.
*/
clientPrefix: "PUBLIC_",
client: {
PUBLIC_CLERK_PUBLISHABLE_KEY: z.string().min(1),
},
/*
* Specify what values should be validated by your schemas above.
*/
runtimeEnv: process.env,
});