Inherited from v1.0.0

dotenv module

Read .env-style files into a map. Handles KEY=value, quoted values ("...", '...'), export KEY=value, comments, and blank lines.

import "dotenv" as dotenv;

var env = dotenv.load_or_empty(".env");
print(env.DATABASE_URL);
print(env.API_KEY);

API

FunctionDescription
dotenv.parse(text) → mapParse a .env-style string into a key/value map.
dotenv.load(path) → mapRead the file, then parse. Throws if missing.
dotenv.load_or_empty(path) → mapSame, but returns an empty map if the file is missing. Useful for optional local overrides.

Supported syntax

  • KEY=value — bare value, trims surrounding whitespace.
  • KEY="quoted value" / KEY='literal' — quoted forms (no escape expansion in v1).
  • export KEY=value — bash-style export prefix is stripped.
  • # comment — full-line comments and blank lines are ignored.

Not supported

  • Shell-style variable interpolation ($VAR and the brace form).
  • Backslash escape sequences inside quoted values.
  • Multi-line values.

See also

  • sys — read process env via sys.env(). Layering .env over real env is a common pattern.