DOCUMENTATION
ENV VARIABLES
Advanced Configurations

Advanced Configurations

Handling Multiple .env Files

You can load multiple .env files and merge their values:

loadEnv({ path: [".env", ".env.local"] });

Variables in .env.local override those in .env if duplicate keys exist.


Configurable Override Behavior

By default, loadEnv() overrides existing environment variables in process.env. You can disable this behavior:

loadEnv({ override: false });

Variable Interpolation

.env file:

BASE_URL="http://example.com"
API_URL="$BASE_URL/api"

Usage:

loadEnv();
console.log(process.env.API_URL); // "http://example.com/api"

Debugging Mode

To enable debug logs:

loadEnv({ debug: true });

Logs all loaded environment variables and warnings.


Copyright © 2024 - 2025 MIT by Mario Elvio