A small .env parser written entirely in Lumen.
This package is intentionally pure: it parses strings only. It does not read files and does not mutate the process environment.
import { get, has, parse } from "https://lumen-lang.org/package/std-contrib/dotenv/dotenv.ts";
let src = "PORT=3000\nAPP_MODE=production\n";
let port = get(src, "PORT", "8080");
let hasMode = has(src, "APP_MODE");
let entries = parse(src); // ["PORT=3000", "APP_MODE=production"]
| API | Meaning |
|---|---|
parse(src: string): string[] | Parse .env text into KEY=value entries |
get(src: string, key: string, fallback: string): string | Return the last value for key, or fallback |
has(src: string, key: string): bool | Return whether key exists |
KEY=value## is preceded by whitespace\n, \r, \t, \", \\export KEY=valueDuplicate keys are allowed. get returns the last value, matching common dotenv behavior.
Malformed lines are ignored in V1 rather than throwing, which keeps the package small and convenient for CLI-style config. A strict parser can be added later if callers need diagnostics.
Test:
lumen test packages/dotenv/dotenv.ts