Skip to content

detectEnvironment

detectEnvironment(env?): "local" | "development" | "ci" | "test" | "preview" | "production" | "agent"

Defined in: detect-environment.ts:19

The environment a process is running in: HOLOCRON_ENVIRONMENT, else ENVIRONMENT, when it names one (any case, with the usual spellings such as production and staging), otherwise ci inside CI and local anywhere else. Unlike environment.get() it reads only those two names (not ENV or NODE_ENV, which many tools set for their own reasons) and never falls back to prod, so a laptop is never mistaken for production. They win over CI, so a deploy job can say it is prod.

Record<string, string | undefined> = process.env

"local" | "development" | "ci" | "test" | "preview" | "production" | "agent"

detectEnvironment({ HOLOCRON_ENVIRONMENT: "production" }); // "production"
detectEnvironment({ ENVIRONMENT: "production" }); // "production"
detectEnvironment({ CI: "true" }); // "ci"
detectEnvironment({}); // "local"