I have some of a database set up with PostgreSQL, and I am able to do everything I need from the psql REPL sort of thing, but when I try to access this though node.js on the same machine I get an password authentication filed for user"[my user name]"
error.
As per an online tutorial, my database acces code is something like this:
var pg = require('pg');
var path = require('path');
var connectionString = require(path.join(__dirname, '../', '../', 'config'));
var client = new pg.Client(connectionString);
client.connect();
var query = client.query('CREATE TABLE items(id SERIAL PRIMARY KEY, text VARCHAR(40) not null, complete BOOLEAN)');
query.on('end', function() { client.end(); });
But as I already have the tables set up with some of my own functions, I'm simply trying to access those functions on POSTs, with:
var express = require('express');
var router = express.Router();
var pg = require('pg');
var path = require('path');
var connectionString = 'postgres://localhost:5432/[My User Name]?ssl=true;
router.post('/locations', function(req,res) {
var client = new pg.Client(connectionString);
client.connect();
var query = client.query([Call to my function, works in REPL, something like "SELECT * FROM create_location([Data from req])"]);
});
I have my pg_.conf set up as:
local all postgres peer
local all all trust
local all all 127.0.0.1/32 trust
host all all ::1/128 md5
your connectionstring seems to be wrong. a connection string has to be like:
postgres://[username]:[password]@[host]:[port]/[databasename]
and in your case:
postgres://[username]@localhost:5432/[databasename]?ssl=true
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With