5

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?

asked Jun 24, 2011 at 11:00
0

1 Answer 1

9

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');
});
answered Jun 24, 2011 at 14:24

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.