GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - vercel/flags: Flags SDK by Vercel

BranchesTags
Open more actions menu

Latest commit

 

History

435 Commits
435 Commits

Folders and files

NameName
Last commit message
Last commit date
.changeset
.changeset
 
 
.github
.github
 
 
.husky
.husky
 
 
.zed
.zed
 
 
apps
apps
 
 
assets
assets
 
 
docs
docs
 
 
examples
examples
 
 
packages
packages
 
 
patches
patches
 
 
scripts
scripts
 
 
skills
skills
 
 
tests
tests
 
 
.gitignore
.gitignore
 
 
.node-version
.node-version
 
 
.npmrc
.npmrc
 
 
.nvmrc
.nvmrc
 
 
.prettierignore
.prettierignore
 
 
.syncpackrc.json
.syncpackrc.json
 
 
AGENTS.md
AGENTS.md
 
 
LICENSE.md
LICENSE.md
 
 
README.md
README.md
 
 
biome.json
biome.json
 
 
package.json
package.json
 
 
pnpm-lock.yaml
pnpm-lock.yaml
 
 
pnpm-workspace.yaml
pnpm-workspace.yaml
 
 
renovate.json
renovate.json
 
 
tsconfig-base.json
tsconfig-base.json
 
 
turbo.json
turbo.json
 
 
vitest.config.ts
vitest.config.ts
 
 

Repository files navigation

hero illustration

Flags SDK

The feature flags toolkit for Next.js and SvelteKit.

From the creators of Next.js, the Flags SDK is a free open-source library that gives you the tools you need to use feature flags in Next.js and SvelteKit applications.

  • Works with any flag provider, custom setups or no flag provider at all
  • Compatible with App Router, Pages Router, and Routing Middleware
  • Built for feature flags and experimentation

See flags-sdk.dev for full docs and examples.

Upgrading from version 3? See the Upgrade to v4 guide.

Installation

Install the package using your package manager:

npm install flags

Setup

Create an environment variable called FLAGS_SECRET.

The FLAGS_SECRET value must have a specific length (32 random bytes encoded in base64) to work as an encryption key. Create one using node:

node -e "console.log(crypto.randomBytes(32).toString('base64url'))"

Use a separate FLAGS_SECRET value for each environment (Development, Preview, Production), and mark the Preview and Production values as Sensitive. Run the generator once per environment to produce distinct values, then store each on Vercel:

vercel env add FLAGS_SECRET production --sensitive --value <production-secret>
vercel env add FLAGS_SECRET preview --sensitive --value <preview-secret>
vercel env add FLAGS_SECRET development --value <development-secret>

This secret is required to use the SDK. It is used to read overrides and to encrypt flag values in case they are sent to the client and should stay secret.

Usage

Create a file called flags.ts in your project and declare your first feature flag there:

// app/flags.tsx
import { flag } from "flags/next";

export const exampleFlag = flag<boolean>({
  key: "example-flag",
  decide() {
    return true;
  },
});

Call your feature flag in a React Server Component:

// app/page.tsx
import { exampleFlag } from "./flags";

export default async function Page() {
  const example = await exampleFlag();
  return <div>{example ? "Flag is on" : "Flag is off"}</div>;
}

Feature Flags can also be called in Routing Middleware and API Routes.

Adapters

The Flags SDK has adapters for popular feature flag providers including LaunchDarkly, Optimizely, and Statsig.

Documentation

There is a lot more to the Flags SDK than shown in the example above.

See the full documentation and examples on flags-sdk.dev.

About

Flags SDK by Vercel

flags-sdk.dev

Resources

Readme
MIT license

Security policy

Security policy
Activity
Custom properties

Stars

629 stars

Watchers

29 watching

Forks

92 forks
Report repository

Releases

Used by

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.