I have an issue with Async function with post request. I don't success to sendback a string value.
Here is the code
exports.GetQuote = async (req, res, next) => {
try{
var dim = req.body.dimension;
test = new sreq({ ** A LOT OF DATA ** })
const data = JSON.stringify(test);
request.post({
headers: { 'content-type': 'application/json' },
url: 'https://www.xxxx.com/API',
body: data
}, (error, res, body) => {
if (error) {
console.error(error)
console.log('ERROR REQUEST');
return
}
datares = JSON.parse(body);
console.log(datares.value+" "+datares.Code); ***VALUE IS OK***
response = datares.value+" "+datares.Code;
return response; *** NOT RETURN VALUE ***
});
}catch (e){
console.error(e);
}
}
the console.log is correct in nodejs console, but it dont't return the value ?
Have i missed something?
Thanks for Help