app.get('/some_endpoint', function (req, res) {
function getData() {
pool.query('SELECT * FROM users WHERE id = $1', [40], (error, res) => {
if (error) {
throw error
}
console.log(res.rows[0]); // this logs the correct output
return res.rows[0];
});
}
let data = getData();
console.log(data); // this logs undefined
});
I can't get data
from the query, for some reason it is undefined sometimes, and sometimes it is not ---0\_/0\_/0---