1

thanks for the help first.

So my problem is: I'm using request in node.js to parse a list o links and I want to get this data in an array then pass to mongoose

function running(link,name,title)
{
    try{
    request.get(link,function(error,response,body){
        return some-data
    })
}
    catch(error){
        console.log(error)
    }  
};

but if I do this

lstPttn1.forEach(function(data){
        //Final link with date pattern
        var lnkFnal = data.site + datReq;
        lst.push(running(lnkFnal,data.nome,data.titulo)))

    });

because request is assynchronous it get a empty list, I'm pretty newbie at assynchronous so I tried to find a solution but didn't find anything like with request, how can I make this happen?

Thanks for the help

EDIT:--------

So I found this post Link of Post

and just added this past on my request code.

count++     
if(count==lstPttn1.length){                 
console.log(lstFnal)
}
1
  • Since you tagged your question [promise], it looks like you actually do have an idea what the solution is. Make running return a promise for the data. Commented May 12, 2017 at 5:03

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.