loadServerEnv
Reads the env files of a mode for server code: .env.public, .env, .env.local and their mode variants, layered as described in readEnvFiles.
Reads the env files of a mode for server code: .env.public, .env, .env.local and their mode variants, layered as
described in readEnvFiles. Every key is returned, not only the public ones; the result is for process.env and
never reaches a client bundle on its own (the browser gets only the public names, and reading another one is the
ENV_NOT_PUBLIC build error).
Import#
ts
import { loadServerEnv } from "@shadow-js/dusk/vite";
Signature#
ts
function loadServerEnv(mode: string, envDir: string): Record<string, string>
Parameters#
| Name | Description |
|---|---|
mode |
Vite's mode (development, production, or a custom one). |
envDir |
The folder of the env files. |
Returns#
The variables of the files. The real environment is not included.
Examples#
ts
loadServerEnv("development", "/app"); // { DATABASE_URL: "postgres://localhost/dev", ... }