Skip to content

ssssota/typedotenv

Repository files navigation

typedotenv

dotenv utility for TypeScript

Example

.env

API_KEY=qwertyuiop
NEXT_PUBLIC_API_BASE_URL=http://example.com/

env.ts (generated TypeScript code)

/* Auto generated by typedotenv */
if (typeof process.env.API_KEY !== 'string') throw new Error('API_KEY is not defined in .env');
export const API_KEY = process.env.API_KEY;
if (typeof process.env.NEXT_PUBLIC_API_BASE_URL !== 'string') throw new Error('NEXT_PUBLIC_API_BASE_URL is not defined in .env');
export const NEXT_PUBLIC_API_BASE_URL = process.env.NEXT_PUBLIC_API_BASE_URL;

disableRuntimeTypeCheck:true & enableTypeAssetion:true & envObject:'import.meta.env'

/* Auto generated by typedotenv */
export const API_KEY = import.meta.env.API_KEY as string;
export const NEXT_PUBLIC_API_BASE_URL = import.meta.env.NEXT_PUBLIC_API_BASE_URL as string;

Usage