@juriadams/env
A simple and type-safe way to validate environment variables.
Install
bun add @juriadams/env
import { vars, optional } from '@juriadams/env';
const env = vars([
'OPENAI_API_KEY',
optional('PORT'),
] as const);
In case one or more of the configured environment variables is missing, an InvalidEnvironmentError
is thrown. This error cann be matched via instanceof
:
import { vars, InvalidEnvironmentError } from '@juriadams/env';
try {
const env = vars(['OPENAI_API_KEY'] as const);
} catch (err
if (err instanceof InvalidEnvironmentError)
console.debug({ missing: err.missing });
throw err;
)
Lifecycle
Develop
bun run dev
Build
bun run build
Types
bun run typecheck
Test
bun run test