Type-Safe Environment Variables
Validate and type your environment variables with confidence
Framework-agnostic, type-safe environment variable validation for TypeScript & JavaScript. Validates at startup, masks secrets, and protects against DoS attacks.
Quick Install
npm install @liahus/safe-envQuick Example
Define your environment schema with a simple DSL and get fully typed, validated variables.
import { env } from "@liahus/safe-env";
const ENV = env({
DATABASE_URL: "string:url",
PORT: "number:default=3000",
NODE_ENV: "enum:development,production,test",
JWT_SECRET: "string:min=32:secret",
});
// ENV is fully typed! 🎉
console.log(ENV.PORT); // 3000 (number, not string!)
console.log(ENV.NODE_ENV); // "development" | "production" | "test"Why safe-env?
Type-Safe
Full TypeScript inference. Numbers are numbers, enums are union types. No more string coercion or type assertions.
Security First
Secrets fully masked in errors. DoS protection built-in. Input validation limits prevent malicious inputs.
Framework Agnostic
Works everywhere: Node.js, Bun, Deno, Next.js, Express, Fastify, NestJS, Vite, Webpack, and more.
Get Started
Start using safe-env in your project in minutes.