@ende/dotenv
ende add jsr:@ende/dotenvVersion 2026.10.15 on JSR.
Parses and stringifies data in the .env file format.
Note: The key needs to match the pattern /^[a-zA-Z_][a-zA-Z0-9_]*$/.
import { parse, stringify } from "@ende/dotenv";
import { assertEquals } from "@ende/assert";
assertEquals(parse("GREETING=hello world"), { GREETING: "hello world" });
assertEquals(stringify({ GREETING: "hello world" }), "GREETING='hello world'");
Migrating from load()
load, loadSync and the @ende/dotenv/load side-effect
module are deprecated in favor of the runtime's
--env-file
flag:
ende run --env-file app.ts
ende run --env-file=.env --env-file=.env.local app.ts
| Deprecated API | Replacement |
|---|---|
import "@ende/dotenv/load" |
ende run --env-file app.ts |
load({ export: true }) / loadSync({ export: true }) |
--env-file |
load({ envPath: "./.env_prod" }) |
--env-file=.env_prod |
load() (read into an object, no export) |
parse(await Ende.readTextFile(".env")) |
Differences to be aware of:
load()silently ignores a missing file.--env-filewarns but continues, while theparse()replacement above throws. To treat the file as optional:
import { parse } from "@ende/dotenv";
let env: Record<string, string> = {};
try {
env = parse(await Ende.readTextFile(".env"));
} catch (e) {
if (!(e instanceof Ende.errors.NotFound)) throw e;
}
$VARinside a double-quoted value stays literal withload()but expands with--env-file. Use single quotes for values containing a literal$.${KEY:-default}and nested defaults are not supported by--env-file. Useparse, which keeps the full expansion behavior.- On platforms without a CLI, e.g. Deno Deploy, set environment variables through the platform's configuration instead.
Modules
@ende/dotenv/load— Loads environment variables from a `.env` file into the process environment as a side effect of importing this module.@ende/dotenv/parse@ende/dotenv/stringify
Exports
load— Load environment variables from a `.env` file. Loaded variables are accessible in a configuration object returned by the `load()` function, as well as optionally exporting them to the process environment using the `export` option.LoadOptions— Options for load and loadSync.loadSync— Works identically to load, but synchronously.parse— Parse `.env` file output in an object.stringify— Stringify an object into a valid `.env` file format.