I am following this guide to query Node.js to Postgres
My code:
NodeJS:
server.listen(port, () => {
console.log(`> Ready on http://localhost:${port}`);
c = db.getUsers();
console.log(c);
});
const getUsers = (request, response) => {
pool.query('SELECT * FROM users', (error, results) => {
if (error) {
throw error
}
//console.log(results) do return data
return results.rows[0].name //results not working either
})
}
console.log(results) return
Result {
command: 'SELECT',
rowCount: 2,
rows:
[ { id: 1, name: 'Jerry', email: 'jerry@example.com' },
{ id: 2, name: 'George', email: 'george@example.com' } ],
}
When I npm run dev
I get
> Ready on http://localhost:3000
undefined
SO any way so that I can get results
data?