0

I am trying to connect to postgres from my node project. So far this is my code

var pg = require('pg');
var connectionString = 'postgress://username:mypssword@localhost:5432/dbname';
var client = new pg.Client(connectionString);
client.connect(function(err) {
 if (err) {
 console.log(err);
 }
});

I get this error:

{
 [Error: connect ECONNREFUSED]
 code: 'ECONNREFUSED',
 errno: 'ECONNREFUSED',
 syscall: 'connect' 
}

I really need help on this

asked Apr 17, 2014 at 0:29
1
  • 2
    Don't forget to accept an answer, you get 2 rep for it, and it helps people in the future figure out what they need. Commented Apr 21, 2014 at 21:17

3 Answers 3

4

it should be postgres:// not postgess:

also you could use an object instead of the string as documented here: pg.Client

answered Apr 17, 2014 at 10:16
1
  • Changing it from a string into an object actually made this one work for me. Cheers. Commented Dec 17, 2014 at 23:14
2

Error: connect ECONNREFUSED means that you're trying to connect to something that won't allow it (and thus is refusing the connection). Make sure your connectionString is correct. The one issue I can see from here is that it starts with:

postgress://

instead of

postgres://

(You have an extra s).

answered Apr 17, 2014 at 0:36
0

I was also facing the same issue for a local Postgres connection. Here your application is not able to establish a connection with Postgres database. Try this solution for Windows OS, replace string "localhost" with "host.docker.internal".

So your new URL will be

postgres://DbUser:[email protected]:5432/DbName
wscourge
11.4k17 gold badges65 silver badges87 bronze badges
answered Mar 27, 2019 at 13:39

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.