I'm having an issue getting the SDK set up in a Ne...
# ask-questions
I'm having an issue getting the SDK set up in a Nest JS environment, but really all I'm trying to do is create a class that contains the configuration for growthbook and provides some wrapping functions. No errors are being thrown when initializing growthbook, but it always returns the default value passed to
- anyone else experienced this?
Here's the code:
Copy code
import {PatientAppUserInfo} from '@ciitizen/back-end-apps-patient-app-nestjs'
import {extractEmailDomain} from '@ciitizen/common-utils'
import {Experiment, GrowthBook, Result} from '@growthbook/growthbook'
import {Injectable} from '@nestjs/common'

type FeatureFlagKey = 'test-2'

const gb = new GrowthBook({
  apiHost: '<https://cdn.growthbook.io>',
  clientKey: '<redacted>',
  enableDevMode: true,
  subscribeToChanges: false,
  trackingCallback: (experiment: Experiment<any>, result: Result<any>): void => {
    // TODO: Make amplitude available on the backend to send events

export class ExperimentationService {
  private _growthbook: GrowthBook

  constructor() {
    this._growthbook = gb

  async getCohort({user, featureFlagKey}: {user: PatientAppUserInfo; featureFlagKey: FeatureFlagKey}): Promise<string> {
    await this._growthbook.loadFeatures()

    await this._growthbook.setAttributes({
      emailDomain: extractEmailDomain(user.email),
      id: user?.authTokenInfo.auth0UserId,

    const defaultValue = 'not enabled'
    let result = defaultValue
    // while (result === defaultValue) {
    result = this._growthbook.getFeatureValue(featureFlagKey, defaultValue)
    // }
    return result
that looks okay
can you do some more debugging? Is it making the network request? do the features load?
No, it is not making the network requests. The features do not load. I created a dummy next JS project to validate that the package works in a blank server context and the features were retrieved successfully, which leads me to be there is something about the NestJS environment which is preventing requests from being made.