← Files NeonARCHIVED FILE
skills/neon/references/parse-env.md
1.37 KB · Oct 4, 2026 · 18:02 UTC
# Type-safe env vars with parseEnv
`@neon/env`'s `parseEnv` takes your `neon.ts` config object and returns a parsed, typed env object, validated against the services you declared. The shape of `env` follows your config, and missing variables are flagged with clear errors.
```bash
npm i @neon/env
```
```typescript
import { parseEnv } from "@neon/env";
import config from "./neon";
const env = parseEnv(config);
console.log(env.postgres.databaseUrl);
console.log(env.auth.baseUrl);
```
By default `parseEnv` requires _every_ variable your config implies. When one of your apps only uses a subset, for example when you need to read `DATABASE_URL` but never the unpooled URL, pass an array of env-var keys to require and validate only those. The keys are typesafe: autocomplete only offers variables your config enables, and the returned shape is narrowed to exactly what you selected (so unselected variables are neither enforced nor present).
```typescript
import { parseEnv } from "@neon/env";
import config from "./neon";
// Only DATABASE_URL is required and returned; DATABASE_URL_UNPOOLED is not enforced.
const { postgres } = parseEnv(config, ["DATABASE_URL"]);
console.log(postgres.databaseUrl);
// Selecting across services — only these keys are validated.
const env = parseEnv(config, ["DATABASE_URL", "NEON_AUTH_BASE_URL"]);
console.log(env.postgres.databaseUrl, env.auth.baseUrl);
```
SHA-256: f43eb0d40570b06437ea3a93662ab528bad4d5c44c9c28c45f993aaa269e10bd