Last updated

.env file parsing, exposed as std/env (there is no separate std/dotenv module). Values support $VAR expansion against earlier keys.

const env = require("std/env");const src = [  "PORT=3000",  "HOST=localhost:$PORT",  "DEBUG=true",  ""].join("\n");const cfg = env.parse(src);for (const key of Object.keys(cfg)) {  console.log(key + "=" + cfg[key]);}// PORT=3000// HOST=localhost:3000// DEBUG=trueconsole.log(env.stringify({PORT: "3000", HOST: "localhost"}));env.load();            // reads ./.env into process envenv.load(".env", true); // ...overwriting existing vars

🔗dotenv.parse

env.parse(text) -> object (with variable expansion applied)

const env = require("std/env");const cfg = env.parse(src); // src aboveconsole.log(cfg.HOST); // "localhost:3000"

🔗dotenv.load

env.load([path][, override]) -> undefined (writes into process env)

const env = require("std/env");env.load("/tmp/demo.txt", true);