Skip to content

oopsio/envdotx

Repository files navigation

envdotx

A hyper-lightweight, multi-runtime .env loader and CLI.

Clocking in at just ~1.1KB, envdotx automatically detects your JavaScript environment (Node, Bun, or Deno) and uses the fastest native APIs available to load your environment variables. If native APIs aren't available, it falls back to a highly optimized custom parser.

Features

  • Universal Runtime: Works seamlessly across Node.js, Bun, and Deno.
  • Insanely Small: Zero dependencies, bundled and minified to ~1.1KB.
  • Native Speed: Uses built-in C++ loaders (like Node 20+ process.loadEnvFile or Bun.env) when possible for zero-overhead parsing.
  • Dual Purpose: Use it as a terminal CLI or import it as a library in your code.

Installation

Pick your favorite package manager:

npm install envdotx
# or
bun add envdotx
# or
yarn add envdotx

CLI Usage

You can use envdotx directly from your terminal to inject variables into other commands or inspect your .env file.

Run a command with environment variables injected:

npx envdotx run -- node server.js
# or with bun
bunx envdotx run -- bun run dev

List all parsed variables in a clean table:

npx envdotx list

Library Usage

You can import envdotx directly into your project. It automatically detects the runtime and applies the variables to process.env, Bun.env, or Deno.env accordingly.

loadEnv(options)

Loads the .env file into the global environment.

import { loadEnv } from "envdotx";

// Automatically loads variables from ./.env
await loadEnv();

console.log(process.env.MY_SECRET);

// You can also specify options:
await loadEnv({
  path: "./custom/.env.local",
  override: true, // Overwrite existing environment variables
});

parse(src)

If you just want to parse a string into an object without modifying the global environment, use the standalone parser.

import { parse } from "envdotx";
import { readFileSync } from "node:fs";

const raw = readFileSync(".env", "utf-8");
const config = parse(raw);

console.log(config); // { KEY: "VALUE" }

getRuntimeName()

Utility to check which runtime envdotx detected.

import { getRuntimeName } from "envdotx";

console.log(`Running on: ${getRuntimeName()}`); // 'node', 'bun', or 'deno'

License

MIT

About

A hyper-lightweight, multi-runtime .env loader and CLI.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors