get-dotenv can power a standalone, generated CLI that you embed in your projects. This approach is great when you want a fixed command surface with minimal code in the host repository.
The plugin-first host (GetDotenvCli
) resolves dotenv context once per invocation and provides:
--trace
diagnostics).If you need custom commands, richer composition, or programmatic hooks, prefer the plugin host. You can still expose the same ergonomics as a CLI while enjoying better structure and observability.
The generator produces a Command
wired with the base options, a default cmd
subcommand, and the batch
subcommand. You can set defaults from a getdotenv.config.json
and forward variables to subprocesses.
Example:
# JSON config + .local variant, and a CLI skeleton named "acme"
npx getdotenv init . \
--config-format json \
--with-local \
--cli-name acme \
--force
This scaffolds:
getdotenv.config.json
(and .local
variant if requested)src/cli/<name>/index.ts
Inside npm scripts, prefer the parent-level alias form to ensure flags apply to getdotenv rather than the inner shell command:
{
"scripts": {
"env-print": "getdotenv -c 'node -e \"console.log(process.env.APP_SETTING ?? \\\"\\\")\"'"
}
}
Then:
npm run env-print -- -e dev
See also: