A thin wrapper around dotenv for providing consistent experience with loading environment variables across different runtimes.
Install using npm
npm install dotenv@latest @tqman/env@latest
Install using bun
bun install dotenv@latest @tqman/env@latest
Environment variables are loaded in the following order:
- .env
- .env.{mode} (mode is NODE_ENV lowercased, default is development)
- .env.local
Strategy is a mix of both bun, vite.
[!NOTE]
Difference from Bun's strategy - bun only supports .env.{mode} when mode is production, development or test. Issue: https://github.com/oven-sh/bun/issues/9090
[!NOTE]
Difference from Vite's strategy - .env.{mode}.local is loaded by default in vite, but not by this library.
As a side effect import
import "@tqman/env/load";
As a function call
import { load } from "@tqman/env";
load();