Skip to main content

Type-Safe Environment Variables

A standalone TypeScript implementation of Vite’s loadEnv with type-safe parsing, Docker secrets support, and optional fallback values.

Quick Start

Get up and running with Load Env in three simple steps.

1

Install the package

Install Load Env using your preferred package manager.
npm install @natoboram/load_env
2

Load environment variables

Call loadEnv() at the start of your application to load variables from .env files.
import { loadEnv } from "@natoboram/load_env"

await loadEnv()
Environment variables are loaded in this order: .env.${NODE_ENV}.local, .env.${NODE_ENV}, .env.local, .env
3

Access type-safe variables

Use dedicated functions to parse environment variables with type safety.
import { envString, envInt, envBool, envUrl } from "@natoboram/load_env"

export const API_URL = envUrl("API_URL")
export const PORT = envInt("PORT", 3000)
export const DEBUG = envBool("DEBUG", false)
export const NODE_ENV = envString("NODE_ENV", "development")

Explore Documentation

Learn how to use Load Env effectively in your TypeScript projects.

Loading Env Files

Understand how .env files are loaded and prioritized

Environment Variables

Parse environment variables with type safety

Docker Secrets

Load secrets from files using Docker secrets

Type Safety

Leverage TypeScript for bulletproof configuration

Key Features

Everything you need for robust environment variable management.

Vite-Style Loading

Load environment variables from .env files with the same priority order as Vite

Type-Safe Parsing

Dedicated functions for booleans, dates, numbers, URLs, UUIDs, and enums with automatic validation

Docker Secrets

Load secrets from files for secure Docker and Kubernetes deployments

Optional & Fallbacks

Support for optional variables and default fallback values for flexible configuration

Ready to get started?

Install Load Env and start managing your environment variables with type safety today.

View Quickstart Guide

Build docs developers (and LLMs) love