Skip to content

Feature/unify env loader#366

Open
Devadakene wants to merge 7 commits into
ChainForgee:mainfrom
Devadakene:feature/unify-env-loader
Open

Feature/unify env loader#366
Devadakene wants to merge 7 commits into
ChainForgee:mainfrom
Devadakene:feature/unify-env-loader

Conversation

@Devadakene

@Devadakene Devadakene commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Closes #255
Summary

This PR consolidates and unifies the environment file resolution logic. Previously, .env file resolution was duplicated in both main.ts and app.module.ts with minor differences in search order, introducing potential configuration drift between application bootstrap and Nest module initialization.

A new loadEnv() helper has been introduced in src/common/utils/env-loader.ts to unify the candidate search order and loading. Both entry points now call this helper.

OS environment variables take precedence over dotenv variables (default dotenv behavior), which has been documented.

Testing

Tested using unit tests in test/env-loader.spec.ts to assert that both call paths agree on the resolved path and load variables consistently.

bun test test/env-loader.spec.ts

Output:

bun test v1.3.14 (0d9b296a)

test\env-loader.spec.ts:
(pass) loadEnv and Call Path Agreement > should resolve process.cwd() / .env if it exists [0.79ms]
(pass) loadEnv and Call Path Agreement > should fallback to app/backend/.env if process.cwd()/.env does not exist [0.25ms]
(pass) loadEnv and Call Path Agreement > should default to first candidate if none exist [0.20ms]
(pass) loadEnv and Call Path Agreement > asserts both call paths (main.ts loading and app.module.ts config path) agree on the final env state [0.32ms]

 4 pass
 0 fail
 8 expect() calls
Ran 4 tests across 1 file. [171.00ms]

Screenshots

Checklist

  • Tests added or updated for new/changed behavior
  • Existing tests pass
  • No secrets, keys, or seed phrases committed
  • Follows the coding conventions in the relevant service README
  • PR is focused on a single concern

Copy link
Copy Markdown
Contributor

Awesome work on this! Thanks for the contribution 🚀 Merging now.

Copy link
Copy Markdown
Contributor

Hi 👋 Thanks for this PR! There are some merge conflicts with the current main. Could you rebase onto main and push when you have a moment? Once it's clean we'll get it merged 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Move env-file loading into a shared helper

2 participants