Skip to content

Node --env-file, Bun and Deno

How Node --env-file, Bun and Deno load environment variables, and one npx getmyenv run command that works for all three.

Oct 10, 2026 · 4 min read

An encrypted padlock leads to one terminal command, which starts Node, Bun or Deno.
One getmyenv run command starts Node, Bun or Deno with the same values.

1. Node: the environment wins over --env-file

When a name is in the environment and in the --env-file file, Node keeps the environment value. A missing file stops Node with an error.

npx getmyenv run -- node server.js

With runtime, remove --env-file=.env only from scripts that load that file. run already puts the values in the environment, and node stops with an error when the file is missing. If a script must keep it, --env-file-if-exists=.env goes on when the file is gone.

2. Bun loads .env files on its own

Bun reads .env, .env.local and the file named for NODE_ENV, like .env.production, without being asked. To be sure the app sees only the context's values, turn the files off:

npx getmyenv run -- bun run --no-env-file index.ts

Or delete the files once the app starts with run.

3. Deno asks for --allow-env

Deno reads no .env file unless you pass --env-file. Reading the environment needs --allow-env, which can name the variables:

npx getmyenv run -- deno run --allow-env=DATABASE_URL,API_KEY main.ts
ts
const url = Deno.env.get("DATABASE_URL");

4. The same run for all three

npx getmyenv run -- node server.js
npx getmyenv run -- bun run --no-env-file index.ts
npx getmyenv run -- deno run --allow-env main.ts

getmyenv runs on Node 24 or newer, so Node must be installed where Bun or Deno starts. run does not read .env files. Delete them when you are ready. npx getmyenv run --explain lists every name and where it comes from. Never values.

Related docs: How run works, Languages, Run the CLI