Skip to content

tanishqmanuja/consistent-env

Repository files navigation

@tqman/env

A thin wrapper around dotenv for providing consistent experience with loading environment variables across different runtimes.

📦 Install

Install using npm

npm install dotenv@latest @tqman/env@latest

Install using bun

bun install dotenv@latest @tqman/env@latest

⚙️ Loading Strategy

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: oven-sh/bun#9090

Note

Difference from Vite's strategy - .env.{mode}.local is loaded by default in vite, but not by this library.

👨‍💻 Usage

As a side effect import

import "@tqman/env/load";

As a function call

import { load } from "@tqman/env";

load();