I would like to dynamically display the variable that I get using this Async function:
async function makeGetRequest() {
res = await axios.get(url);
xml2js.parseString(res.data, function (err, file) {
return file.item[0].title; });
}
makeGetRequest().then(console.log);
**OUTPUT: TITLE:[object Promise]**
Instead of logging the value like in the above snippet, I'd like to pass the value to Express renderer to dynamically render the value on a page:
app.get('/dynamic', function(req, res){
res.render('dynamic', {
title: title_value_here;
});
});
Could someone show how this can be achieved?
I tried storing the Async output in variable to then pass it to renderer but I got this:
let out= await makeGetRequest();
console.log(author);
SyntaxError: await is only valid in async functions and the top level bodies of modules