Node Js quota policy - not able to access result attributes

Not applicable

I am using quota policy in node js - apigee access module and want to access quota result attribute on each request.

Below is sample:

var In_Range = "";

var countUsed = "";

quota.apply( {identifier:key1,allow:2,timeUnit:'minute'}, //600 seconds

function(err, result) {

if (err) {

console.log('Quota Limit Exceeded Error--'+err);

}else {

In_Range = result.isAllowed;

countUsed = result.used; } } );

console.log('This value is coming empty outside quota policy block: %j', countUsed);

0 1 82
1 REPLY 1

Hi @Waqar Syed,

Sorry there was no reply to your question. Did you ever get it to work? As you probably know, the variables are being set in an asynchronous callback function. Your console.log actually executes before those variables are set in the callback function, which is why they're coming up empty outside the quota block. Maybe the async module could help you out or using Promises. If someone else has a suggestion, please feel free to chime in.

Will