0

I an a newbie to javascript/nodejs. I am currently trying to access data from one of the open weather API's using the request something like

var url='http://api.openweathermap.org/data/2.5/weather?q=${city}&units=imperial&appid=${apikey}'; resBody=request(url, function(err,res,body){ return body}

when I do a console.log(body) inside the function i get the expected results but same is not available on console.log(resBody) the results are different.

What am I missing. Can you please help here.

nehalkum
  • 11
  • 1
  • 4
  • Well yes. `resBody = request(stuff)`, that returns a `request` operation (an object). Whereas `body` is the _result_ of the request operation, after it's completed. Requests and calls are asynchronous. – Jeremy Thille Jul 11 '18 at 12:55
  • That `return` does not do what you think it is doing. Need to learn the basics of promises and asynchronous requests – epascarello Jul 11 '18 at 12:56

0 Answers0