Not sure what I'm missing here but the console.log() line prints "Promise { }" instead of the JSON body from the response.
I believe that I'm doing something wrong with async/await.
My code (Express):
async function axiosPost(url, payload) {
try {
const res = await axios.post(url, payload);
const data = await res.data;
return data;
} catch (error) {
console.error(error);
}
}
app.get('/data', (req, res) => {
data = axiosPost('http://localhost:8080', {
userpass: 'XXX',
method: 'getdata'
});
console.log(data)
res.status(200).send({
message: data
})
});
Any help is appreciated.