0

I'm tyring to make a connection from my nodejs script to my db connection, but seems like there is a suspicius issue i'm not able to figure out.

At the moment, this is my code:

const { Pool } = require('pg');
const pool = new Pool({
    user: 'user',
    host: '192.168.1.xxx',
    database: 'database',
    password: 'password',
    port: 5432,
});
pool.on('error', (err, client) => {
    console.error('Error:', err);
});
const query = `SELECT * FROM users`;
pool.connect()
    .then((client) => {
        client.query(query)
            .then(res => {
                for (let row of res.rows) {
                    console.log(row);
                }
            })
            .catch(err => {
                console.error(err);
            });
    })
    .catch(err => {
        console.error(err);
    });

The issue seems to be in pool.connect(), but i can't understand what i'm missing because i got no errors in the log. I've installed pg module in the directory of my project with npm install --prefix pg and i know modules are loaded correctly. I edited postgresql.conf:

# - Connection Settings -
listen_addresses = '*'

and pg_hba.conf

host    database       user          192.168.1.0/24          md5

to make the database reachable via lan and seems liek it works, because i'm able to connect successfully with apps like DBeaver...but i can't with NodeJS.

It's possible there is some kind of configuration i've to active?

Loris
  • 101
  • 7
  • Is the username `user` or `users`? What credentials do you use in DBeaver? What is the error you are getting? – Bergi May 24 '20 at 18:12
  • the username of the database is 'user' and the table is 'users' (it's just an example). I use the same credential i try to use with nodejs. I get no error in the log, but it doesn't work. If i put a console.log in the .then function, it doesn't write anything. – Loris May 24 '20 at 18:32
  • Please post your package.json if any. Also: what NodeJS version are you using? I suspect: https://stackoverflow.com/questions/61611039/postgres-server-is-not-responding-to-a-nodejs-request/61615233#61615233 – madflow May 25 '20 at 07:12

0 Answers0