Tuesday, 6 June 2017

How to connect to postgresql locally with node.js on Ubuntu 16.04?

Soo I am using Digitalocean droplet and used this tutorial https://www.digitalocean.com/community/tutorials/how-to-install-and-use-postgresql-on-ubuntu-16-04 to set it up. The postgres works on the machine when I connect using my user.

When I try to connect to the postgres database using node.js it doesn't work.

var pg = require('pg');
var conString = "postgres://myuser:password@localhost:5432/dbname";

var client = new pg.Client(conString);
client.connect();

When I look at the node.js error logs it says that

error: password authentication failed for user "myuser"
    at Connection.parseE (/usr/lib/node_modules/pg/lib/connection.js:572:11)
    at Connection.parseMessage (/usr/lib/node_modules/pg/lib/connection.js:396:$
    at Socket.<anonymous> (/usr/lib/node_modules/pg/lib/connection.js:132:22)
    at emitOne (events.js:96:13)
    at Socket.emit (events.js:188:7)
    at readableAddChunk (_stream_readable.js:176:18)
    at Socket.Readable.push (_stream_readable.js:134:10)
    at TCP.onread (net.js:547:20)

I'm not sure what password it is meaning. The only password I have entered is the one I used to create myuser on Ubuntu just like the tutorial instructed. I'm sure that the password matches the one I entered for myuser. I also tried to leave it blank but that's not working either.

But I assume the connection works, and only the authentication fails? Is there some default password for new postgres databases?



via Quartal

No comments:

Post a Comment