@natoboram/load_env is a standalone implementation of Vite’s loadEnv function that provides a simple and type-safe way to manage environment variables in your Node.js applications.
What is Load Env?
Load Env helps you:- Load environment variables from
.envfiles automatically - Ensure type safety with dedicated functions for different data types
- Handle secrets from the filesystem (Docker Compose secrets support)
- Provide fallback values for environment variables
- Parse complex types like URLs, UUIDs, dates, and enums
Key Features
Automatic Loading
Automatically loads
.env files based on NODE_ENV with proper precedence handlingType Safety
Type-safe functions for booleans, numbers, strings, URLs, UUIDs, dates, and more
Secret Management
Built-in support for Docker Compose secrets and filesystem-based secrets
Fallback Support
Provide default values for environment variables that might not be set
How It Works
Load Env follows a simple loading strategy based onNODE_ENV:
Set NODE_ENV
The
NODE_ENV environment variable determines which .env files to load. If not set, it defaults to development.Load .env files
Environment variables are loaded in order of precedence:
.env.${NODE_ENV}.local(highest priority).env.${NODE_ENV}.env.local.env(lowest priority)
NODE_ENV must be set in the environment and will not be picked up from .env files.Example Usage
Here’s a quick example of how to use Load Env:When to Use Load Env
Node.js Applications
Perfect for backend applications, CLI tools, and scripts that need environment configuration
Docker Deployments
Seamless integration with Docker Compose secrets for secure credential management
Multiple Environments
Easy management of development, staging, and production configurations
Type-Safe Config
Applications that benefit from compile-time type checking of configuration values
Next Steps
Installation
Install Load Env in your project via npm, yarn, pnpm, or JSR
Quick Start
Get started with a working example in minutes
