repo-env
v1.0.1
Published
A lightweight, zero-config package that automatically loads environment variables for monorepos.
Maintainers
Readme
repo-env
A lightweight, zero-config package that automatically loads environment variables for monorepos (Turborepo, pnpm, npm, Yarn, Bun workspaces).
Installation
npm install repo-env
# or
pnpm add repo-env
# or
yarn add repo-env
# or
bun add repo-envUsage
Just import and call loadEnv() at the very top of your application entry point:
import { loadEnv } from "repo-env";
loadEnv();Or you can use CommonJS:
const { loadEnv } = require("repo-env");
loadEnv();Loading Order
repo-env automatically detects your workspace root and your current app directory, loading variables in the following priority (later files override earlier ones):
root/.envroot/.env.localroot/.env.{NODE_ENV}root/.env.{NODE_ENV}.localapp/.envapp/.env.localapp/.env.{NODE_ENV}app/.env.{NODE_ENV}.local
API & Configuration
import { loadEnv } from "repo-env";
loadEnv({
// The directory to start searching from. Defaults to process.cwd()
cwd: process.cwd(),
// The mode to load environment files for. Defaults to process.env.NODE_ENV || "development"
mode: "production",
// Whether to override already-existing environment variables. Defaults to false.
override: true,
// Whether to log which files were loaded. Defaults to false.
verbose: true,
});