Hi all,This is probably really stupid but I've consulted a lot of resources and am still really stuck on parts of this concept. I just really would like a straightforward answer.So basically, I'm building my first NodeJS project and I'm trying to request a lot of info from links using the request module.Here's a snippet (not the whole thing) of one of the things I'm trying to accomplish:function returnBodyExample(){ requestOptions.url = 'file.json'; request(requestOptions, function(error, response, body){ return body }); This gives undefined.All I want is to be able to use the body parameter outside of the callback function's body, but I have no idea how to do it. I've noticed I can just assign the value to a global object and use it from there, but I have a feeling that's not best practice. Then certain things I try, I end up with undefined (as in this example), whereas others I get Promise { body } or Promise { undefined }. I don't even know what to do when I get those promises. Clearly I just don't get the concept.Thanks so much if you can help ;__;
Submitted July 11, 2019 at 03:45AM by thx4theadvice
No comments:
Post a Comment