I'm extracting some data from the database, to use it in my nodejs app. I'm using node-postgres to connect to the db (https://node-postgres.com/).
I went through the guidance multiple times and tried querying it in different ways (callback, promise, using pool and client), but always get errors.
const { Pool } = require('pg');
const pool = new Pool({
user: 'user',
host: 'host',
database: 'db',
password: 'pass',
port: port,
});
pool.query('SELECT * from table').then(res=> {
var projects = res.rows;
console.log(projects);
return projects;
});
//... few other operations on projects data to follow before exports
exports.raw = projects;
I can see the data in the console output, so the connection is working, but when I try to run the code I get
ReferenceError: projects is not defined.
Grateful for any help with this.