What I am trying to do is to make a request to a Web API and then if the input is valid return true from a function and if it is not valid return false. I want the request to be async but I don't want the function to return before the request is validated. While the request is being made, I just want to continue to process input.
Here is the important part of the function:
request({
url: url,
json: true
}, function (error, response, body) {
if (!error && response.statusCode === 200) {
console.log(JSON.stringify(body));
if(body.player !== "null") {
console.log(body.player.socialMedia.links["DISCORD"]);
console.log((client.users.get(author).username + "#" + client.users.get(author).discriminator));
if (body.player.socialMedia.links["DISCORD"] === (client.users.get(author).username + "#" + client.users.get(author).discriminator)) {
fs.writeFile(`users/${body.player.uuid}.json`, `{"uuid":"${body.player.uuid}",\n"ign":"${nm}",\n"id":"${author}"}`, {"flag": "w"});
successFlag = true;
}
}
}
});
console.log(successFlag);
return successFlag;
If I use async/await I am unsure if input will continue to be processed while the data is fetched.