Thursday 21 February 2019

Need help with simple code

First off, I'm totally new to nodejs, and javascript in general. Basically I want to access the x variable outside the request method. Now x is just "{}" outside the reqeust method, but what I want it to be inside the request method. I think the problem has something to do with async, but not quite sure.I'm using the "request" package, and the code below is simplified.​function func() { let x = {}; request(url, function (error, response, body) { x = JSON.parse(body); }); return x; }Thank you​

Submitted February 21, 2019 at 07:19PM by bjabot

No comments:

Post a Comment