loadEnvx Usage
Parses a .envx file and injects the validated variables into process.env.
loadEnvx()
The loadEnvx()
function reads a .envx
file, validates its contents based on the defined schema, and injects all environment variables into process.env
.
It’s designed for development and server-side environments where you want the configuration available globally, without needing to explicitly pass it around in your application.
🔧 What It Does
- Locates and parses the
.envx
file - Validates the variables using inline or external schema
- Injects all key–value pairs into
process.env
- Returns the validated result as a typed object
Example
// does not support typed, only ideal for processing to process
import { loadEnvx } from "typenvx";
loadEnvx();
console.log(process.env.API_URL); // string | undefined
console.log(env.DEBUG_MODE); // string | undefined
or
// types/envx.ts - generated via `npx typenvx types`
export interface EnvVars {
API_URL: string;
DEBUG_MODE?: boolean;
}
import { loadEnvx } from "typenvx";
const env = loadEnvx<EnvVars>();
console.log(env.API_URL); // string
console.log(env.DEBUG_MODE); // boolean | undefined