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 🙏

© 2024 – Pkg Stats / Ryan Hefner

fflip-express

v1.0.2

Published

FFlip integration for the Express web framework

Downloads

2,169

Readme

fflip-express

fflip-express is an Express.js integration for the fflip feature-flagging library.

npm install fflip-express --save

Configuration

var FFlipExpressIntegration = require('fflip-express');

// The first `fflip` argument is the fflip module used in your application
// The second `options` argument is optional, and lets you configure your integration
var fflipExpress = new FFlipExpressIntegration(fflip, options);

Available configuration options include:

  • cookieName: The name of the cookie where a users manual feature flags will be saved. (Defaults to 'fflip')
  • cookieOptions: Set additional options for the fflip cookie, such as expires & maxAge. (No default)
  • manualRoutePath: The URL path for the manual feature flipping endpoint. Must include both :name and :action route params. (Defaults to '/fflip/:name/:action')

Usage

This integration provides two different ways to connect fflip into your express application:

fflipExpress.middleware

app.use(fflipExpress.middleware);

req.fflip: A special fflip request object is attached to the request object, and includes the following functionality:

req.fflip = {
  setForUser(user): Given a user, attaches the features object to the request (at req.fflip.features). Make sure you do this before calling has()!
  has(featureName): Given a feature name, returns the feature boolean, undefined if feature doesn't exist. Throws an error if setForUser() hasn't been called
}

Use fflip in your templates: Once setForUser() has been called, fflip will include a Features template variable that contains your user's enabled features. Here is an example of how to use it with Handlebars: {{#if Features.closedBeta}} Welcome to the Beta! {{/if}}

Use fflip on the client: Once setForUser() has been called, fflip will also include a FeaturesJSON template variable that is the JSON string of your user's enabled features. To deliver this down to the client, just make sure your template something like this: <script>var Features = {{ FeaturesJSON }}; </script>.

fflipExpress.manualRoute

// Feel free to use any route you'd like, as long as `name` & `action` exist as route parameters.
app.get('/custom_path/:name/:action', fflipExpress.manualRoute);

A route for manually flipping on/off features: If you have cookies enabled, you can visit this route to manually override a feature to always return true/false for your own session. Just replace ':name' with the Feature name and ':action' with 1 to enable, 0 to disable, or -1 to reset (remove the cookie override). This override is stored in the user's cookie under the name fflip, which is then read by fflip.expressMiddleware() and req.fflip automatically.

fflipExpress.applyAll(app)

Sets up the express middleware and route automatically. Equivilent to running:

app.use(fflipExpress.middleware);
app.get(fflipExpress.options.manualRoutePath, fflipExpress.manualRoute);