npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

nestjs-flags

v0.0.5

Published

A flexible feature flag module for NestJS applications

Readme

npm version Build Status Coverage Status License: MIT

Description

nestjs-flags provides a simple way to implement feature flags (also known as feature toggles) in your NestJS application. It integrates with the standard @nestjs/config module to load flag statuses and offers a Guard and Decorator (@FeatureFlag) to control access to routes based on whether a feature is enabled or disabled.

Features

  • Loads flags from configuration (via @nestjs/config).
  • Provides NestjsFlagsService for imperative flag checks.
  • Provides @FeatureFlag() decorator and FeatureFlagGuard for declarative route protection.
  • Configurable via forRoot options (custom config key, custom exception on disabled flag).
  • Written in TypeScript with types included.
  • Unit tested.

Installation

npm install nestjs-flags
# or
yarn add nestjs-flags

Quick Start

  1. Configure your flags: Set up your flag configuration source, for example, using a .env file:

    # Feature flags (prefix matches default 'featureFlags' key mapping)
    FEATURE_FLAGS_NEW_USER_PROFILE=true
    FEATURE_FLAGS_EXPERIMENTAL_SEARCH=false
  2. Import ConfigModule and NestjsFlagsModule: In your main application module (e.g., app.module.ts), import and configure @nestjs/config and NestjsFlagsModule.

    // src/app.module.ts
    import { Module, ForbiddenException } from "@nestjs/common";
    import { ConfigModule } from "@nestjs/config";
    import { AppController } from "./app.controller";
    import { AppService } from "./app.service";
    import { NestjsFlagsModule } from "nestjs-flags"; // Import the module
    
    @Module({
      imports: [
        ConfigModule.forRoot({
          isGlobal: true,
          envFilePath: ".env",
          load: [finalConfig],
        }),
    
        NestjsFlagsModule.autoLoadFromEnv(),
      ],
      controllers: [AppController],
      providers: [AppService],
    })
    export class AppModule {}
  3. Use the Service or Decorator:

    • Using NestjsFlagsService: Inject the service to check flags programmatically.

      // src/app.controller.ts
      import { Controller, Get, Logger } from "@nestjs/common";
      import { NestjsFlagsService } from "nestjs-flags";
      
      @Controller("service-example")
      export class ServiceExampleController {
        constructor(private readonly flagsService: NestjsFlagsService) {}
      
        @Get("feature")
        getFeature() {
          if (this.flagsService.isFeatureEnabled("newUserProfile")) {
            return { message: "New user profile is available!" };
          } else {
            return { message: "Showing the old profile." };
          }
        }
      }
    • Using @FeatureFlag Decorator and Guard: Protect entire routes declaratively.

      // src/app.controller.ts
      import { Controller, Get, UseGuards, Logger } from "@nestjs/common";
      import { FeatureFlag, FeatureFlagGuard } from "nestjs-flags";
      
      @Controller("decorator-example")
      export class DecoratorExampleController {
        private readonly logger = new Logger(DecoratorExampleController.name);
      
        @Get("profile")
        @UseGuards(FeatureFlagGuard) // Activate the guard
        @FeatureFlag("newUserProfile") // Specify the flag to check
        getProfileFeature() {
          // This code only runs if 'newUserProfile' is true
          this.logger.log("Guard allowed access to profile.");
          return { message: "Showing the NEW user profile!" };
        }
      
        @Get("search")
        @UseGuards(FeatureFlagGuard)
        @FeatureFlag("experimentalSearch")
        getSearchFeature() {
          // This code only runs if 'experimentalSearch' is true
          // If false, the guard throws an exception (NotFoundException by default)
          this.logger.log("Guard allowed access to search.");
          return { message: "Using the EXPERIMENTAL search!" };
        }
      }