Postgresql on nodejs

nodejs
postgresql

#1

How to connect to postgresql on nodejs?

db = pgp(‘postgres://ubuntu:password@host:’+process.env.PORT+’/mydatabase’);

on the page:
Error: getaddrinfo ENOTFOUND host host:8080
at errnoException (dns.js:27:10)
at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:78:26)


#2

what the port for postgressql database?


#3

ok, I guess it must be
db = pgp(‘postgres://ubuntu:password@localhost:5432/mydatabase’);
but now I get ‘password authentication failed for user “ubuntu”’


#4

oh ok, I fixed this by
\password [new pass]


#5

i had the same problems hooking up to nodejs, pretty much. i didn’t realize postgresql was pre installed. i have only really used mlab or firebase in the past. anyways, this tutorial thing i’m doing is using this package sequelize, and i figured why not try something new.
i finally figured out the port and created my database but i kept getting an error. long story short, the error was asking me to install an npm module called pg. once i did that i was good to go. the pg site mentions something about binaries or bindings or something? im not super familiar with all that but just running npm i pg solved my problem. i even removed it and then reinstalled, sure enough the app would not connect once i uninstalled pg.
also, probably good to explain that \password <db_username> is how you get to password prompt. the tips above are changing the user/role postgres password. idk but when i went in and made my first table it was under the user ubuntu so i had to go in and change the password for that user to get things working.