Stack Overflow is a community of 4.7 million programmers, just like you, helping each other.

Join them; it only takes a minute:

Sign up
Join the Stack Overflow community to:
  1. Ask programming questions
  2. Answer and help your peers
  3. Get recognized for your expertise

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

share|improve this question
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. – SomeKittens Apr 21 '14 at 21:17
up vote 2 down vote accepted

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).

share|improve this answer

it should be postgres:// not postgess:

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

share|improve this answer
    
Changing it from a string into an object actually made this one work for me. Cheers. – Michael Thelin Dec 17 '14 at 23:14

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.