Node server cannot connect to postgres db

I recently switched from MySQL to postgres as my database for the node.js. project Although I can access my remote postgres database from my local pgAdmin III (OSX) client, so far I have not been able to connect to my database through node.js. I am sure that the credentials entered for pgAdmin and my node.js were exactly the same. Another thing I tried was that my local ipadress trusted instead of md5 in pg_hba.conf on my database server. Am I doing something wrong? My favorite search engine came up with some disturbing hits about rebooting my local OS. I just used the example from the github repo node-postgres document:

var pg = require('pg'); var conString = "postgres://myusername: mypassword@hostname :5432/dbname"; var client = new pg.Client(conString); client.connect(function(err) { if(err) { return console.error('could not connect to postgres', err); } client.query('SELECT NOW() AS "theTime"', function(err, result) { if(err) { return console.error('error running query', err); } console.log(result.rows[0].theTime); client.end(); }); }); 

And these are the errors that I get every time I try to start my server:

 could not connect to postgres { [Error: getaddrinfo ENOTFOUND] code: 'ENOTFOUND', errno: 'ENOTFOUND', syscall: 'getaddrinfo' } 

Help will be greatly appreciated

+6
source share
2 answers

It seems that node-postgres does not accept the hashtag in your password. After removing the hashtag, I was able to contact without problems. I would not think about it, and it did not seem to me a problem, since pgAdmin accepted it.

+21
source

The interface in node.js that I used can be found here https://github.com/brianc/node-postgres

  var pg = require ('pg');
 var conString = "postgres: // YourUserName: YourPassword@localhost : 5432 / YourDatabase";

try changing pg: // to postgres: //

This was cleared from another stackoverflow article: How to connect to Postgres via node.js

0
source

All Articles