Я следую этому руководству , чтобы запросить Node.js до Postgres
Мой код:
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 (результаты) return
Result {
command: 'SELECT',
rowCount: 2,
rows:
[ { id: 1, name: 'Jerry', email: 'jerry@example.com' },
{ id: 2, name: 'George', email: 'george@example.com' } ],
}
Когда я npm run dev
, я получаю
> Ready on http://localhost:3000
undefined
ТАК любым способом, чтобы я мог получить results
данные?