Reputation: 4550
Trying to connect to postgres using the pg client (following these instructions).
Here is my connection string var connectionString = "postgres://postgres:pass@localhost/ip:5432/chat";
Here's the error I'm getting trying to connect:
UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): error: database "ip:5432/twitchchat" does not exist
However, when I run pg_isready
I get the response /tmp:5432 - accepting connections
Which I read as telling me postgres is running on port 5432.
The database is very definitely existing.
Here's the simple connection code:
var pg = require('pg');
var connectionString =
"postgres://postgres:pass@localhost/ip:5432/chat";
var connection = new pg.Client(connectionString);
connection.connect();
What's happening here? How do I fix this?
Upvotes: 0
Views: 1102
Reputation: 4550
Ok I fixed it with the following:
const { Client } = require('pg');
const connection = new Client({
user: 'postgres',
host: 'localhost',
database: 'chat',
password: 'pass',
port: 5432,
});
connection.connect();
Upvotes: 0
Reputation: 22989
Your connection string is malformed:
Change it to:
`"postgres://postgres:pass@localhost:5432/chat"`
The correct format is:
postgresql://[user]:[password]@[address]:[port]/[dbname]
Upvotes: 1