From 951844836fca55b5321999a4d4637d1b56fdb448 Mon Sep 17 00:00:00 2001 From: Autumn Date: Mon, 11 May 2026 17:47:44 +0100 Subject: [app] added .env support --- src/lib/dotenv.ts | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 src/lib/dotenv.ts (limited to 'src/lib') diff --git a/src/lib/dotenv.ts b/src/lib/dotenv.ts new file mode 100644 index 0000000..2fb8e65 --- /dev/null +++ b/src/lib/dotenv.ts @@ -0,0 +1,28 @@ +// +// ~~~ read a .env file +// + +// imports +import { readFileSync } from "node:fs" + +// load .env function +export default function loadDotenv() { + + const file: string = ".env" // todo: don't hard-code the location + + try { + + const fileContents = readFileSync(file, "utf8") + .split("\n") + .filter((line) => line !== "") + .map((line) => line.split("=")) + + const fileEntries = new Map(fileContents) + return Object.fromEntries(fileEntries) + + } catch(e) { + + console.error("!> cannot read .env file") + + } +} -- cgit v1.3