Add an Environment Variable

Jet uses @ngx-env/builder, which automatically exposes environment variables prefixed with NG_APP_.

Let's say you want to add an environment variable BASE_URL. We'll add the required prefix and name it NG_APP_BASE_URL.

Step 1: Add it to the Env interface:

env.d.ts
declare interface Env {
  readonly NG_APP_BASE_URL: string; // Add
  readonly NODE_ENV: string;
}

declare interface ImportMeta {
  readonly env: Env;
}

Step 2: Add it to /.env:

.env
NG_APP_BASE_URL=https://example.com/api

Step 3: Add it to your CI pipeline:

Environment variable in CI pipeline
Environment variable in CI pipeline

Step 4: Access it using import.meta.env.NG_APP_BASE_URL ?? ''. Always provide a fallback value to prevent your app from crashing when an environment variable isn't found.

Last updated