@quark-fw/plugin-env
v0.1.32
Published
.env plugin for the Quark framework: every env var as an atom, live-reloaded via chokidar (published as raw TS sources; consumers run tsx)
Readme
@quark-fw/plugin-env
.env plugin for Quark apps: every environment variable is an atom (quark.env.get("KEY")), the .env file in the working directory is loaded on init and re-read when it changes (chokidar), and every change emits env:changed.
Install
npm i @quark-fw/plugin-envPeer: @quark-fw/core.
Usage
import "@quark-fw/plugin-env"; // provides quark.env, watches ./.env
quark.env.get("FEATURE_FLAG").value; // Atom<string | undefined>, initial value from process.env
quark.env.has("REDIS_URL"); // true if seen by the plugin or present in process.env
const unsubscribe = quark.env.subscribe("FEATURE_FLAG", (value) => {
/* reacts to .env edits at runtime */
});
quark.env.set("FEATURE_FLAG", "on"); // updates the atom and emits env:changed
quark.ee.value.on("env:changed", (key, value) => {});How it works: atoms are created lazily per key with process.env[key] as the initial value. On init the plugin parses .env at process.cwd() (KEY=VALUE lines, # comments; the value is everything after the first =, trimmed, quotes are not stripped) and calls quark.env.set for each line, then watches the file (awaitWriteFinish) and reloads it on change. set() writes the atom only — process.env is not modified, so code that reads process.env directly keeps the startup value. The watcher is closed in onDestroy.
Env: no fixed names — the plugin reads process.env[<key>] for whatever key is requested, plus the ./.env file.
Part of the Quark framework.
