Answer the question
In order to leave comments, you need to log in
Why can't I define this query?
const getdata = (async function() {
return {
cities: await new Promise((res, rej) => {
connection.query('SELECT * FROM posts', (err, result) => {
if (err) throw err
res(result)
})
}),
posts: await new Promise((res, rej) => {
connection.query('SELECT * FROM posts', (err, result) => {
if (err) throw err
res(result)
})
})
}
})()
console.log(getdata);
Promise { <pending> }
Answer the question
In order to leave comments, you need to log in
why is IIFE here? and yes, async functions return a promise. necessaryconst getdata = await (async function() {...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question