You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

nuxt-feature-flags

Package Overview
Dependencies
Maintainers
0
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install
Package version was removed
This package version has been unpublished, mostly likely due to security reasons

nuxt-feature-flags

Feature flags for Nuxt

0.0.2
unpublished
Source
npmnpm
Version published
Weekly downloads
63
-41.12%
Maintainers
0
Weekly downloads
 
Created
Source

Nuxt Feature Flags 🚩

npm version npm downloads License Nuxt

A feature flag module for Nuxt 3 with context-aware evaluation and server-side support, inspired by @happykit/flags.

Features

  • 🎯  Context-aware evaluation (user, environment, cookies)
  • ⚡  Server-side evaluation
  • 🛠  TypeScript ready
  • 🔍  Explanation system for flag states
  • 🧩  Nuxt 3 composables integration
  • 🔧  Runtime configuration support

Quick Setup

  • Add the module to your Nuxt project:
npx nuxi module add nuxt-feature-flags
  • Create a context file:
// ~/feature-flags.context.ts
import { parseCookies } from 'h3'
import { detectDevice } from '~/utils/device'

export default function featureFlagsContext(event: any) {
  return {
    user: event?.context.user,
    cookies: parseCookies(event),
    device: detectDevice(event),
    environment: process.env.NODE_ENV
  }
}
  • Configure in nuxt.config.ts:
export default defineNuxtConfig({
  modules: ['nuxt-feature-flags'],
  featureFlags: {
    contextPath: '~/feature-flags.context',
    flags: {
      experimentalFeature: (context) => context.user?.isBetaTester
    },
    defaultContext: {
      environment: process.env.NODE_ENV
    }
  }
})
  • Use in components:
<script setup>
const { isEnabled, get } = useFeatureFlags()
</script>

<template>
  <div>
    <NewDashboard v-if="isEnabled('newDashboard')" />
    <div v-if="get('experimentalFeature')?.explanation">
      Flag reason: {{ get('experimentalFeature')?.explanation?.reason }}
    </div>
  </div>
</template>

Configuration

Module Options

interface ModuleOptions {
  flags?: Record<string, FlagDefinition>
  defaultContext?: Record<string, any>
  envKey?: string
  contextPath?: string
}

Example Configuration

// nuxt.config.ts
export default defineNuxtConfig({
  featureFlags: {
    contextPath: '~/feature-flags.context',
    flags: {
      promoBanner: true,
      userSurvey: { percentage: 50 },
      betaFeature: (ctx) => ctx.user?.tier === 'premium'
    },
    defaultContext: {
      environment: process.env.NODE_ENV
    },
    envKey: 'NUXT_PUBLIC_FEATURE_FLAGS'
  }
})

Documentation

Context File

Create a file at the specified contextPath (default: ~/feature-flags.context.ts) that exports a function:

export default function featureFlagsContext(event: any) {
  return {
    // Your context properties
  }
}

The function receives the Nitro event and should return an object with the evaluation context.

Composables

const { 
  flags,       // Reactive flags object
  isEnabled,   // (flagName: string) => boolean
  get          // <T>(flagName: string) => Flag<T> | undefined
} = useFeatureFlags()

Flag Definitions

type FlagDefinition =
  | boolean
  | ((context: EvaluationContext) => boolean)

Contribution

Contributions are welcome! Please follow these steps for local development:

# Install dependencies
npm install

# Develop with playground
npm run dev

# Lint code
npm run lint

License

MIT License © 2025 Roberth González

Keywords

nuxt

FAQs

Package last updated on 22 Feb 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts