Skip to main content

Concern

Loading environment variables from .env files into process.env (Node) or for use at config time (e.g. Vite).

Technology

dotenv

Documentation

Version

v17

Implementation

  • Backend: The backend does not call dotenv in main.ts. @nestjs/config (ConfigModule) loads .env files via envFilePath (from getEnvFilePaths() in backend/src/config/env-paths.ts) and maps BACKEND_* to unprefixed keys inside the validate function (mapAndValidate in backend/src/config/env.validation.ts). See backend configuration for the full flow. dotenv is used internally by Nest's ConfigModule when loading envFilePath; the backend need not add dotenv as a direct dependency unless other code uses it.
  • Frontend (desktop): dotenv is a devDependency. In frontends/desktop/vite.config.ts, at config load time, call config({ path: ... }) to load the root .env so Vite and any custom env mapping (e.g. FRONTEND_DESKTOP_*VITE_*) see the same vars. Add dotenv to desktop devDependencies. See frontend configuration and vite for how the loaded env is used.

Integration

Backend configuration

Backend uses dotenv to load root and backend .env; backend configuration describes the BACKEND_ prefix convention and unprefixing so app code sees PORT, DATABASE_URL, etc.

Frontend configuration / vite

The desktop Vite config uses dotenv to load the root .env before setting envDir and mapping FRONTEND_DESKTOP_* to VITE_*; see vite and frontend configuration for the full flow.