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?

3
  • Is the username user or users? What credentials do you use in DBeaver? What is the error you are getting? Commented May 24, 2020 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. Commented May 24, 2020 at 18:32
  • Please post your package.json if any. Also: what NodeJS version are you using? I suspect: stackoverflow.com/questions/61611039/… Commented May 25, 2020 at 7:12

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.