Environment variables

Every environment variable the SDK reads, which ones the browser can see, and which one wins.

.env.local
NEXT_PUBLIC_FLAGGISH_CLIENT_KEY=your-client-key

# Optional
NEXT_PUBLIC_FLAGGISH_ENV=production
NEXT_PUBLIC_FLAGGISH_API_URL=https://flags.example.com
NEXT_PUBLIC_FLAGGISH_REACH=false

Only the client key is required. In Next.js, the NEXT_PUBLIC_ names cover both the server and the browser, so they’re usually all you need.

All variables

VariableSetsValues
FLAGGISH_CLIENT_KEYclientKeyYour client key, from Settings › API keys
NEXT_PUBLIC_FLAGGISH_CLIENT_KEYclientKeyThe same, readable in the browser
FLAGGISH_SECRET_KEYsecretKeyYour secret key, from Settings › API keys. Server only, for list groups. There is no NEXT_PUBLIC_ version
FLAGGISH_ENVenvproduction or development, any case
NEXT_PUBLIC_FLAGGISH_ENVenvThe same, readable in the browser
FLAGGISH_API_URLapiUrlThe API base URL, for a self-hosted API
NEXT_PUBLIC_FLAGGISH_API_URLapiUrlThe same, readable in the browser
FLAGGISH_REACHreachfalse or 0 turn reach off; true or 1 turn it on
NEXT_PUBLIC_FLAGGISH_REACHreachThe same, readable in the browser
NODE_ENVenv, as a last resortproduction reads Production flags; anything else reads Development

The secret key

FLAGGISH_SECRET_KEY is the one variable that must never be readable in a browser. Set it in your server’s environment only, and never give it a NEXT_PUBLIC_ name: the SDK doesn’t read one, and Next.js would write it into your browser code. It’s only needed for list groups. An empty value counts as not set.

Which one wins

For each setting, the SDK uses the first of these that’s set:

  1. the option you pass in code, such as env or clientKey
  2. the plain variable, such as FLAGGISH_ENV
  3. the NEXT_PUBLIC_ variable, such as NEXT_PUBLIC_FLAGGISH_ENV
  4. the default: the NODE_ENV rule for env, the Flaggish API for apiUrl, and on for reach

An empty variable counts as not set. A value the SDK doesn’t recognise for FLAGGISH_ENV or FLAGGISH_REACH is ignored, and it moves on to the next one.

Server and browser

Next.js only exposes NEXT_PUBLIC_ variables to browser code. So FLAGGISH_SECRET_KEY, FLAGGISH_ENV, FLAGGISH_API_URL and FLAGGISH_REACH only apply on the server, and client components fall back to the defaults.

  • To set something for both sides, set the NEXT_PUBLIC_ name.
  • To set it for the server only, set the plain name.
  • To set it for one provider, pass it as a prop to FlaggishProvider or FlaggishServerProvider.

Next.js writes NEXT_PUBLIC_ values into the browser code when it builds, so rebuild after you change one.

With FlaggishServerProvider, set the client key and environment with the NEXT_PUBLIC_ names. If you set only FLAGGISH_ENV, the server reads that environment but the browser reports reach for the environment its own NODE_ENV implies, so those reach events are dropped. If you set only FLAGGISH_CLIENT_KEY, the browser has no key: it sends no reach, and if the server’s fetch failed, the browser can’t fetch the flags itself.

The Next.js server helpers

getFlag, getFlags and getFlaggishConfig take no options, so environment variables are the only way to configure them, including FLAGGISH_SECRET_KEY. For example, FLAGGISH_REACH=false is the way to turn reach off for them.

Node

Plain Node has no browser, so use the plain names:

.env
FLAGGISH_CLIENT_KEY=your-client-key
FLAGGISH_ENV=production
# Optional, for list groups
FLAGGISH_SECRET_KEY=your-secret-key

The SDK reads process.env directly. It doesn’t load .env files, so load them the way you normally do.

Was this page helpful?

Request early access

Become a beta user, or stay up to date with the project.