Load, expand, and compose environment variables from a deterministic dotenv cascade, then execute commands under that context. Use get‑dotenv as a library, a CLI, or a plugin‑first host to build dotenv‑aware tooling with cross‑platform shell control, CI‑friendly capture, and clear diagnostics.
get‑dotenv helps you:
See full guides:
npm install @karmaniverous/get-dotenv
Run a one‑off command with your env (parent alias so flags apply to getdotenv):
npx @karmaniverous/get-dotenv -c 'node -e "console.log(process.env.APP_SETTING ?? \"\")"'
Load programmatically:
import { getDotenv } from '@karmaniverous/get-dotenv';
const vars = await getDotenv({ env: 'dev', paths: ['./'] });
console.log(vars.APP_SETTING);
Embed a CLI quickly (shipped plugins wired for you):
#!/usr/bin/env node
import { createCli } from '@karmaniverous/get-dotenv/cli';
await createCli({ alias: 'toolbox' })();
More first steps and tips at Getting Started
Author config in JSON/YAML/JS/TS at your project root. The loader is always on in the shipped host:
vars (global), envVars (per‑env)rootOptionDefaults, rootOptionVisibilityscriptsdynamicschema, requiredKeysOverlays apply by kind/env/privacy/source with clear precedence. Details and examples in the Config guide.
Add dynamic keys that compute from the composed env. Programmatic or file‑based (JS/TS). For TypeScript, install esbuild for auto‑compile.
// dynamic.ts
export default {
GREETING: ({ APP_SETTING = '' }) => `Hello ${APP_SETTING}`,
};
Learn more in the Config guide formats section.
The shipped CLI is plugin‑first:
cmd subcommand or the parent alias:
getdotenv cmd ... or getdotenv -c 'echo $APP_SETTING'--shell (default OS shell) or --shell-off, and enable capture for CI:
batch plugin]guides/shipped/batch.md--trace [keys...] prints per‑key origin (dotenv | parent | unset) before spawning.GETDOTENV_STDIO=pipe or pass --capture.--redact / --redact-off (+ --redact-pattern for additional key matches).Learn more:
Also see the shipped plugins overview.
The host resolves dotenv context once per invocation, overlays config, validates, and then runs plugins with a typed options bag.
Typed API docs are built with TypeDoc.
See CHANGELOG.md
BSD‑3‑Clause — see LICENSE
Built for you with ❤️ on Bali! Find more great tools & templates on my GitHub Profile.