How to access variable present in node.js file in java script file

ekumar
Participant II

Hi

I have a variable ("myvar") in my node.js file with some value assigned to it.

Now I want to access that variable and get the value of that variable in Java Script file.

For that I have tried with "context.getVariable("myvar")" in java script. But it throws me error that "myvar" is undefined.

so, can anyone please help me in how to get the value of variable.

Thanks.

0 2 124
2 REPLIES 2

We're going to need more context, more code, in order to help explain this and guide you.

Instead of 2 words of code, provide 10 lines or so... provide the relevant code context.

Also you said "my node.js file". Exactly where is that running?

More context.

Hi Sai,

If you are under the impression that simply by declaring a variable in the node.js backend of an api proxy that variable will be accessible in a JS policy, then that is an incorrect assumption.

You can however set the node.js variable in an Apigee flor variable. Refer this Note: However the node.js backend itself is a deprecated feature. Check out Hosted Targets.

Also, as Dino rightfully suggested, help us to to help you by providing more info about what the actual scenario is like.