Hey all! I am new to GrowthBook, and I have a cou...
# ask-questions
Hey all! I am new to GrowthBook, and I have a couple of questions. I had successfully installed and used GrowthBook feature toggles in our frontend app (ReactJS), but I am having trouble doing the same in our backend app (KoaJS). I tried following the JavaScript SDK but without any luck. Does anyone have any insights? More specifically: • Where should I install the Growthbook package? In our main
? And if so, is there any guide that I can follow? • How can I use GrowthBook features inside a service? Consider that some services we use are used directly from other services and are not attached to any route. I want to access the GrowthBook instance on those services. I tried exhausting all possible solutions before deferring to you folks. Any help would be much appreciated. Thanks in advance!
Hi John, I’m not familiar with KoaJS, but it should work. What is the failure mode for the backend not working? an error or the flags are just not working correctly?
👋 Hi Graham, and thank you for the swift response. The failure mode is that I am not getting the features I set up inside the GrowthBook dashboard. Here is a trimmed example of this service:
Copy code
const db = require('db');
const { GrowthBook } = require('@growthbook/growthbook');
const { GROWTHBOOK_SETTINGS } = require('lib/constants/growthbook.constants');

const {
} = require('app.constants');

const service = db.createService(DATABASE_DOCUMENTS.TESTS);

// Initialize GrowthBook
const growthbook = new GrowthBook({


service.completeTest = async (test) => {

   console.log('It should work');
   // I want to trigger a specific event here

  // Some additional business logic...

module.exports = service;
When I console into my client app (ReactJS), I see both features, but when I do the same in the backend, I am not seeing anything. One of my questions is if this is the right place to initialize GrowthBook, or if it should happen on an app level.
huh, I wonder if its a race condition - maybe add an await on the load features call?
We have some examples using Node server side: https://docs.growthbook.io/lib/js#nodejs
Until features are loaded, all features will evaluate to
. If you’re ok with a potential flicker in your application (features going from
to their real value), you can call
without awaiting the result.
If you want to refresh the features at any time (e.g. when a navigation event occurs), you can call
Thanks for the suggestions but I don’t have any luck 😞 I moved the
inside my async function but I am still seeing nothing.
Copy code
try {
      // When features change, update the GrowthBook instance automatically
      // Default: `false`
      autoRefresh: true,
      // If the network request takes longer than this (in milliseconds), continue
      // Default: `0` (no timeout)
      timeout: 2000,
  } catch (error) {
    console.error('Error loading GrowthBook features:', error);
Until features are loaded, all features will evaluate to
Is there any function to check if features are loaded?
Also, is there any channel here to ask for specific help from experts? Paid of course!
I haven't used Koa before, but my understanding is that it's fairly similar to Express. First, check out the NodeJS guide (which is really geared towards Express). Specifically there's a section starting with:
Create a separate GrowthBook instance for every incoming request. This is easiest if you use a middleware:
```// Example using Express
app.use(function(req, res, next) {
// Create a GrowthBook instance and store in the request
req.growthbook = new GrowthBook({
You'd create a middleware of this sort (only Koa-flavored) near the top of your routes, and then subsequent routes would have access. Just be sure to not call
has completed; otherwise your subsequent routes will not have the data available. The example above is Express, but Koa seems to do something quite similar, except that your middleware interface would be
function(ctx, next)
(no req, res). So I believe instead of assigning the GrowthBook SDK to the
object (Express), you'd assign it to Koa's
. Then your downstream routers / controllers would have access to that context variable.