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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@alpha018/nestjs-unleash-client

v1.0.2

Published

A NestJS module for Unleash, providing feature flagging with decorators and a Guard.

Downloads

130

Readme

NestJS Unleash Client

Table of Contents

⚠️ Important: Starting from this version, the minimum required Node.js version is 20.

Installation

$ npm i @alpha018/nestjs-unleash-client

Usage

Import The Module

To use the Unleash client in your application, import the module into your main module. The module registers a global guard that will automatically protect routes decorated with @UnleashToggle.

Static Registration

import { UnleashClientModule } from '@alpha018/nestjs-unleash-client';

@Module({
  imports: [
    // ...
    UnleashClientModule.forRoot({
      config: {
        url: 'http://unleash.herokuapp.com/api/',
        appName: 'my-nestjs-app',
      },
      isGlobal: true, // Make the module and its providers global
    }),
    // ...
  ],
})
export class AppModule {}

Async Registration

import { UnleashClientModule } from '@alpha018/nestjs-unleash-client';
import { ConfigModule, ConfigService } from '@nestjs/config';

@Module({
  imports: [
    // ...
    UnleashClientModule.forRootAsync({
      imports: [ConfigModule],
      useFactory: (configService: ConfigService) => ({
        config: {
          url: configService.get('UNLEASH_URL'),
          appName: configService.get('UNLEASH_APP_NAME'),
          customHeaders: { Authorization: configService.get('UNLEASH_API_TOKEN') },
        }
      }),
      inject: [ConfigService],
      isGlobal: true, // Make the module and its providers global
    }),
    // ...
  ],
})
export class AppModule {}

Parameter Options

Options for forRoot and forRootAsync:

| Parameter | Type | Required | Description | |-----------|-------------------|----------|--------------------------------------------------------------------------------| | config | UnleashConfig | Yes | The configuration object for the unleash-client. See options below. | | isGlobal | boolean | No | If true, the module will be registered as a global module. Defaults to false. |

The config object is passed directly to the unleash-client. The most common options are:

| config Parameter | Type | Required | Description | |--------------------|----------|----------|------------------------------------------------------------------------------------------------------------| | url | string | Yes | The URL of your Unleash server API. | | appName | string | Yes | The name of your application. | | customHeaders | object | No | Custom headers to be sent to the Unleash API. Use Authorization for the API key generated by the Unleash panel. | | ... | any | No | Any other valid option from the official unleash-client-node documentation. |

Protecting a Route with a Feature Toggle

To protect an endpoint with a feature toggle, use the @UnleashToggle decorator. The global UnleashGuard will automatically deny access if the feature is disabled.

import { Controller, Get } from '@nestjs/common';
import { UnleashToggle } from '@alpha018/nestjs-unleash-client';

@Controller()
export class AppController {
  @Get('hello')
  @UnleashToggle('my-feature-toggle')
  getHello(): string {
    // This route is only accessible if 'my-feature-toggle' is enabled in Unleash
    return 'Hello World!';
  }

  @Get('unprotected')
  getUnprotectedHello(): string {
    // This route is always accessible as it does not have the @UnleashToggle decorator
    return 'This is an unprotected route.';
  }
}

Injecting the Unleash Client

If you need to check a feature toggle directly in your code, you can inject the UnleashClientProvider.

import { Controller, Get } from '@nestjs/common';
import { UnleashClientProvider } from '@alpha018/nestjs-unleash-client';

@Controller()
export class AppController {
  constructor(private readonly unleashProvider: UnleashClientProvider) {}

  @Get('check')
  checkFeature() {
    if (this.unleashProvider.isEnabled('my-other-feature')) {
      // Logic for when the feature is enabled
      return 'Feature is enabled!';
    } else {
      // Logic for when the feature is disabled
      return 'Feature is disabled!';
    }
  }
}

Resources

Check out a few resources that may come in handy when working with NestJS:

Stay in touch

License

This project is MIT licensed.