How to Access Variables of node.js file in Java script file

ekumar
New Member

Hi

I have a requirement where I have two variables in my node.js script having some values.

Now, I need to access them in a Java script file after node.js file

What can I do for that. Can anyone help me here.

Thanks in advance.

0 6 798
6 REPLIES 6

Can you tell us more about your Node.js? Are you using the old/deprecated approach using Trireme? (Do you have your Node.js sources in resources/node?) Are you using the new approach using Hosted Targets? (Do you have your Node.js sources in resources/hosted?)

Hi Jeremy,

Thanks for the response.

I was using Trireme approach and the node.js file is a node.

Can you tell me what to do to keep a variable global just like we did in JavaScript as context.setVariable()

If possible,

Can you also tell me how to use in new approach hosted Target and what is the difference between hosted Target and Trireme in accessing variables

The apigee-access module will allow you to do this, just know that Trireme-based proxies and the apigee-access module are deprecated. But using apigee-access will allow you to use context.setVariable(), use that variable in Node.js, etc.

I even tried with that. But I was not able to access the variable in java script file.

Can you tell me exactly on how to keep variable globally using apigee-access with a small example.

apigee-access allows you to fully manage variables. If you set one in JavaScript, you can read/update it from Node.js, and then on the response flow you can read again from JavaScript.