Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

Environment variables for Node.js app

Was going through this page and came across the below:

<TargetEndpoint name="default">
  <ScriptTarget>
     <ResourceURL>node://hello.js</ResourceURL>
     <EnvironmentVariables>
         <EnvironmentVariable name="NAME">VALUE</EnvironmentVariable> 
     </EnvironmentVariables>
     <Arguments>
         <Argument>ARG</Argument>
     </Arguments>
  </ScriptTarget>
</TargetEndpoint>

Here the VALUE cannot be dynamic?

I know, I can use apigee-access module (apigee.getVariable(req,"flow.variable")), to access these in Node. However, I do not always have access to the req parameter all the way down.

Is it possible to set dynamic arguments to Node application via the TargetEndpoint configuration?

In my use case, I would be looking up values on the KVM and these would be fetched by appropriate layers on Node. I do not have to rely on passing the req parameter all the way down, just to access the flow variable (via apigee-access). Any suggestions/alternatives on how to best achieve this?

Thanks,

Girish

Solved Solved
0 3 1,458
1 ACCEPTED SOLUTION

Not applicable

Dear @Girish Gajria, you're right about setting dynamic values from variables in Node.js as environment variables. Therefore, you won't be able to leverage them for the purpose of passing values dynamically. However, based on your use case, you can leverage many other features available in Apigee Edge to retrieve dynamic variables. I'll try to sumarize the ones I'm familiar with:

  • Setting a context variable and access it through apigee-access Node.js Module. It seems that you're already familiar with this option. However, based on your comments, this option doesn't suite your requirements, because the request object is not always available. My only comment to you is that since Node.js is always set as a Target in Edge, the request object should always be present. So, you should be good making this assumption.
  • Setting values through KVMs. This is okay. However, since KVMs aren't directly accessible at this point in Node.js, you'll still need to set the KVM as a variable to make it accessible.
  • Setting the value through Apigee Vault. It is perhaps the most native way to set a dynamic value since apigee-access already supports it.

Am I missing anything?

View solution in original post

3 REPLIES 3