DOCUMENTATION
ENV VARIABLES
Schema Validation

Schema Validation

Defining a Schema for Validation

import { schema, loadEnv, InferOut } from "vkrun";
 
const envSchema = schema().object({
  API_KEY: schema().string(),
  DEBUG: schema().boolean(),
  PORT: schema().number().integer(),
});
 
type EnvsType = InferOut<typeof envSchema>;
 
const envs = loadEnv<EnvsType>({ schema: envSchema });
 
console.log(envs.PORT); // 3000

If validation fails, loadEnv() throws an error, preventing misconfigurations.


Copyright © 2024 - 2025 MIT by Mario Elvio