I'm trying to connect to a postgres database from node.js, but I always get some strange error
ENOTFOUND, Domain name not found
The node.js module that I use is 'pg'.
In few examples I saw different connection strings:
pg://, tcp:// and postgres://
Can you please tell me which one is correct? And what can cause this problem?
Here is some code I used to try giving my PG database a web interface. It's able to connect and insert/delete/select records depending on what command you send via curl or a web browser.
var app = require('express').createServer();
var pg = require('pg');
var conString = "postgres://YOURUSER:YOURPASSWORD@localhost/dev";
var client = new pg.Client(conString);
client.connect();
app.get('/', function(req, res){
res.send('hello world');
});
app.get('/select/:client_id', function(req, res){
var query = client.query("select '{count:}' as c_count,client_id from test_input where client_id = $1 limit 1", [req.params.client_id]);
query.on('row', function(row) {
res.send(row);
});
}
);
app.get('/insert/:client_id',
function(req, res)
{
console.log('called');
client.query("INSERT INTO test_input(client_id) VALUES($1)",[req.params.client_id]);
res.send('done');
});
process.on('uncaughtException', function (err) {
console.log(err);
});
app.get('/delete/:client_id',
function(req, res)
{
console.log('called');
client.query("DELETE FROM test_input WHERE client_id = $1",[req.params.client_id]);
res.send('done');
});
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