Using Feature Flags/Gates in your app is simple and straightforward. This article will show you a step-by-step process of creating a simple Node.js app that responds to feature gate changes in almost-real-time.
If you don’t already have an account, create one for free at https://www.statsig.com/ and create a new Feature Gate named “First App Test”
The first step to creating the Node app in your command line terminal is:
$ mkdir statsigNodeApp && cd statsigNodeApp
$ npm init --yes
This will create a package.json file in the statsigNodeApp directory.
Next, let’s install statsig-node SDK.
$ npm install statsig-node
Now, we’re all set to write our main app’s logic. Here’s the code that checks the gate we just created every second and writes out whether it passes or not. Copy and paste this into a file named index.js.https://medium.com/media/153cc5e35683db3d164c4e419232f32b/href
One last thing is you need to replace the ‘secret-API-KEY’ with your own API key, which you can find in your project’s settings:
With that replaced, you are ready to run this app by issuing this command:
$ node index.js
You will see something like this in the output:
This means that the flag is evaluating to ‘false’ all the time. Let’s go ahead and create a new rule that turns on this feature for everyone.
And let’s make sure to hit that ‘Save Changes’ button.
Now, if we had kept that Node App running, you’ll notice that it has started saying ‘passed’ automatically, since now this feature flag is turned on to everyone.
You can now try turning off this feature in the console.
Which will immediately make the feature fail the check and the app will go from ‘passed’ to ‘failed’ to reflect the change.
Hope this was helpful in getting you started and on your way to creating more complex features! As always we’re here to help out. You can join our Slack community here: https://statsig.com/community.
Explore Statsig’s smart feature gates with built-in A/B tests, or create an account instantly and start optimizing your web and mobile applications. You can also schedule a live demo or chat with us to design a custom package for your business.
This summer I had the pleasure of joining Statsig as their first ever product design intern. This was my first college internship, and I was so excited to get some design experience. I had just finished my freshman year in college and was still working on...
The 95% confidence interval currently dominates online and scientific experimentation; it always has. Yet it’s validity and usefulness is often questioned. It’s called too conservative by some , and too permissive by others. It’s deemed arbitrary...
Statsig’s Journey with Druid This is the text version of the story that we shared at Druid Summit Seattle 2022. Every feature we build at Statsig serves a common goal — to help you better know about your product, and empower you to make good decisions for...
💡 How to decide between leaning on data vs. research when diagnosing and solving product problems Four heuristics I’ve found helpful when deciding between data vs. research to diagnose + solve a problem. Earth image credit of Moncast Drawing. As a PM, data...
Have you ever sent an email to the wrong person? Well I have. At work. From a generic support email address. To a group of our top customers. Facepalm. In March of 2018, I was working on the games team at Facebook. You may remember that month as a tumultuous...
Run experiments with more speed and accuracy We’re pleased to announce the rollout of CUPED for all our customers. Statsig will now automatically use CUPED to reduce variance and bias on experiments’ key metrics. This gives you access to a powerful experiment...