Version: Deno 2.7.5
Summary
According to the documentation, the --env-file flag should automatically load the first .env file found in the current directory or recursively in parent directories. However, in practice it appears to only check the current working directory.
Documentation reference
https://docs.deno.com/runtime/reference/env_variables/
"Deno will look for a .env file in the current working directory or recursively in parent directories."
Reproduction
Directory structure:
parent-folder
.env
child-folder
main.ts
Example .env:
Example main.ts:
console.log(Deno.env.get("FOO"));
Run from child-folder:
deno run -A --env-file main.ts
Expected behavior
Deno should discover and load the .env file located in the parent directory (../.env), resulting in:
Actual behavior
The environment variable is not loaded:
The .env file is only loaded when explicitly specifying the path:
deno run -A --env-file=../.env main.ts
Environment
2.7.5
Additional context
Based on the documentation wording, the --env-file flag appears intended to behave similarly to other tools that search for .env files up the directory tree (e.g., many dotenv implementations). If the current behavior is intentional, the documentation may need clarification.
Version: Deno 2.7.5
Summary
According to the documentation, the
--env-fileflag should automatically load the first.envfile found in the current directory or recursively in parent directories. However, in practice it appears to only check the current working directory.Documentation reference
https://docs.deno.com/runtime/reference/env_variables/
Reproduction
Directory structure:
Example
.env:Example
main.ts:Run from
child-folder:Expected behavior
Deno should discover and load the
.envfile located in the parent directory (../.env), resulting in:Actual behavior
The environment variable is not loaded:
The
.envfile is only loaded when explicitly specifying the path:Environment
2.7.5
Additional context
Based on the documentation wording, the
--env-fileflag appears intended to behave similarly to other tools that search for.envfiles up the directory tree (e.g., many dotenv implementations). If the current behavior is intentional, the documentation may need clarification.