exports.getAddress = asyncHandler(async (req, res, next) => {
var lon = req.query.lon;
var lat = req.query.lat;
var formattedAddress = "";
var url1 = 'url'
request(url1, { json: true }, (err, res, body) => {
if (err) { return console.log(err); }
formattedAddress = body.formattedAddress;
console.log(formattedAddress); // string address showing
});
console.log(formattedAddress); // string is empty
res.status(200).json({ success: true, data: formattedAddress });
});
I read the above and many posts but can't understand how can i get the string value outside of the function.