Hey there, I'm trying to assign the result of a MYSQL query to a JS variable so that I can use it multiple times. However, whenever I try to do this, I end up receiving an empty array. Can anyone point out what might be causing this issue in my code?
app.get('/api/get/db', async (req, res) => {
async function test() {
new Promise((resolve, reject) => {
con.query("SELECT * FROM `temp`", (err, result) => {
resolve(result)
})
})
}
data = await test()
res.status(200).json({data})
})
I have attempted to troubleshoot by adding a return statement, but unfortunately, it's not working as expected.