Sending response in async function

I need to return an array of labels, but I can only return 1 of the labels so far. The error which I get is "Cannot set headers after they are sent to the client". So I tried res.write and placed res.end after my for loop then I get the obvious error of doing a res.end before a res.write. How do I solve this?

for(let i=0;i<arr.length;i++){
request.get(arr[i], function (error, response, body) {
  if (!error && response.statusCode == 200) {
    async function myfunction(){
    const Labels = await Somefunctioncallwhoseresponseigetlater(body)

Read more here:

Content Attribution

This content was originally published by bigdaddy-zephyr at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: