import { defineEnv } from "env-typed-guard";
const env = defineEnv({
PORT: { type: "number", defaultValue: 3000 },
DATABASE_URL: { type: "string" },
DEBUG: { type: "boolean", defaultValue: false },
});Environment variables break
production apps silently.
There is no TypeScript safety for process.env — until now.
Missing env vars
Applications crash at runtime when required variables are forgotten.
Silent Typos
Minor spelling mistakes in .env files lead to hours of debugging.
Production Risks
Teams ship broken configurations unknowingly, risking uptime.
A runtime safety layer for
configuration correctness.
Built for modern backend teams
Everything you need to ship confident Node.js applications.
Type-safe env access
Get full IntelliSense and compile-time safety for your environment variables.
Fail-fast validation
Stop the application immediately if any required config is missing or invalid.
Full TypeScript inference
Automatically derive types from your schema without manual interface definitions.
Runtime validation engine
Strict type checking for numbers, booleans, and enums at process startup.
Enum & Custom validation
Define valid values or custom logic to ensure data integrity.
Zero-dependency core
Lightweight and secure. No external bloat added to your production binary.
defineEnv(schema, config?)
The primary entry point. Define your environment schema once and get a validated, typed object for your entire application.
Supported Types
Extra Features
import { defineEnv } from "env-typed-guard";
const env = defineEnv({
NODE_ENV: {
type: "enum",
validValues: ["dev", "prod", "test"],
defaultValue: "dev",
},
PORT: {
type: "number",
defaultValue: 3000,
validate: (v) => v > 1024
},
DB_URL: {
type: "string",
isSecret: true
},
});Full IntelliSense based on your schema definition.
Instant Clarity on Errors
Stop guessing why your deployment failed. Get human-readable error logs.
Important: Node.js vs Next.js
This library is designed for the Node.js ecosystem. While it works perfectly in Next.js Server Components and API Routes, it is not recommended for Client Components as browsers cannot access environment variables from process.env directly (unless prefixed with NEXT_PUBLIC_ which is handled by Next.js).
Ready to secure your config?
npm install env-typed-guard