async function in request

Not applicable

I am using async function in request of node js API. Its saying warning while saving. But in node js logs, i am getting below error. This is not saying at which line number of my js file. How can i trace where i am writing wrong.

Part of Code Snippet:

request(options, async function(err, res) { if (res.statusCode === 204 && url.indexOf("college_id") > -1) { res = await getDefaultCollegeResponse(url, res); }; callback(err, res); });

Error In Node JS logs.

*** missing ) after argument list missing ) after argument list at module.js:439:0 at module.js:474:0 at module.js:356:0 at module.js:312:0 at module.js:497:0 at startup (trireme.js:142:0) at trireme.js:923:0

But same code works in standalone node js application. Is it expecting ")" after "request(options, async"???

Solved Solved
0 4 867
1 ACCEPTED SOLUTION

Hi @Iranna Teggi, as @Jeremy Whitlock mentioned, Apigee Trireme based Nodejs doesnt support all node modules and async is one of it.

Please have a look at Hosted Targets (Beta). It supports latest Nodejs versions & all modules.

View solution in original post

4 REPLIES 4

Node.js hosting in Edge, the Trireme-based version, does not support async/await.

Hi @Iranna Teggi, as @Jeremy Whitlock mentioned, Apigee Trireme based Nodejs doesnt support all node modules and async is one of it.

Please have a look at Hosted Targets (Beta). It supports latest Nodejs versions & all modules.

Just to be clear, Iranna is not trying to use the "async" module but the "async" keyword in ES2017. Regardless, Trireme does not support it. If you were to use Hosted Targets, you can use a Node.js runtime that supports the "async" keyword from ES2017.

@Siddharth Barahalikar, @Jeremy Whitlock

Yes, now I can understand the limitations. Even tried "Promise" and "fetch". even these are not supported.

And as of now, we cant think of moving to Hosted target Proxy, as it requires a lot of changes.

And to re-iterate the real problem, we were using async.map and calling the APIS and then, if any of the API didnt return the response, we call the fall back API for that loop. But async.map doesn't wait till we receive the fallback API returns the response. It proceeds. So we were trying to use await, promise. But still no luck.

Any suggestion will be helpfull.