Unleash/unleash

docs: How to Implement Feature Flags in Node.js using Unleash

rishi-raj-jain opened this issue ยท 1 comments

Outline ๐Ÿ‘‡๐Ÿป


How to Implement Feature Flags in Node using Unleash

Some additional information

In this tutorial, you will learn how to use feature flags in a [Node.js](https://nodejs.org/) application that toggles new dashboard vs existing dashboard to users based on their email IDs, using Unleash. We will use the unleash-client package, which provides easy integration of Unleash feature flags in a Node.js application.

What weโ€™ll be using

Mention:

  • Tech (It's purpose)
  • Tech (It's purpose)
  • Tech (It's purpose)

What youโ€™ll need

  • Tech (It's purpose)
  • Tech (It's purpose)

Setting up the project

To set up, just clone the app repo and follow this tutorial to learn everything that's in it. To fork the project, run:

git clone https://github.com/rishi-raj-jain/repo-slug
# Some additional information

Scaffolding a Node.js app

Creating an Node.js app is as easy as a single command:

# command

Setup Unleash

  1. Run the following commands in the terminal to fetch the docker-compose.yml for creating an Unleash instance:
wget getunleash.io/docker-compose.yml
docker-compose up -d

This will start Unleash in the background. Once Unleash is running, you can access it at http://localhost:4242/.

  1. Now use the default credentials to log into the instance:
Username: admin
Password: unleash4all

Create a New Feature

Create a new feature flag in your Unleash instance named user-access.

Steps

Screenshots

Integrating Unleash in Node.js app

Installation

To get started with Node.js and Unleash, you need to install unleash-client package as a dependency.

You can run the following commands in your terminal to do this:

npm install unleash-client

Set up Environment Variables

By default, the following values are setup in your local Unleash instance

# .env

UNLEASH_API_URL="http://localhost:4242/api"
UNLEASH_AUTHORIZATION_KEY="default:development.unleash-insecure-api-token"

Initialize Unleash SDK

Some additional information

Create a simple HTTP server with Node.js

Some additional information

// some code

Use Unleash SDK to fetch the feature flag value

This section would be highlighting the use of userId parameter in Unleash constraints.

Some additional information

// some code

Scenarios

Some additional information

Screenshots

Using Unleash in Production

To setup Unleash for production, please follow the steps below:

  1. Self-host Unleash, or run an instance on [Unleash Cloud](https://www.getunleash.io/pricing).
  2. Get an [API key](/reference/api-tokens-and-client-keys) from the Unleash dashboard.
  3. Store the API key in your Environment Variables of your hosting, which secures it and makes it accessible in your code.

Conclusion

Some additional information