Hello, I’m using the JavaScript SDK to implement G...
# contributing
w
Hello, I’m using the JavaScript SDK to implement Growthbook to my api. We are using Sails.js and fetching feature flag values via Sails policy. We are also trying to set attributes inside of the policy right before fetching from GrowthBook API. Do the attributes in the growthbook instance sustain through multiple requests? We are thinking about setting attributes dynamically based on the API call that is coming in, hence there are concerns with race condition depending on how attributes are sustained.
f
Hi Karen. We recommend creating a new GrowthBook instance for each request in backend APIs with the attributes specific to that request.
I'm not very familiar with Sails.js, but in Express for example, you would add a middleware at the start of the request to create a GrowthBook instance and then be able to use it in any API route
w
Creating a new instance will work best for us. Thank you.
@future-teacher-7046 I have a follow-up question from the onboarding session last week. I remembered you said that when a flag is created, it will be best to set the default value to
false
. However, that also means if I enabled an environment, the flag is still not on unless I have a forced rule to specify when the value is true. Is that correct? If I am not using any rules, and all I want to do is to enable the entire environment all at once, is setting the default value to
true
the right way to go?
f
Yeah, if you just want to use the environment toggles and not worry about rules or overrides, then it's fine to set the default value to
true