2011-06-24 28 views
5

मैं Node.js से एक postgres डेटाबेस से कनेक्ट करने के लिए कोशिश कर रहा हूँ Node.js, लेकिन मैं हमेशा कुछ अजीब त्रुटिpostgres कनेक्शन की समस्या

ENOTFOUND, Domain name not found 

Node.js मॉड्यूल मैं का उपयोग करें कि 'PG' है मिल ।

pg://, tcp:// and postgres:// 

क्या आप मुझे बता सकते हैं जो एक सही है:

कुछ उदाहरण में मैं विभिन्न कनेक्शन तार देखा था? और इस समस्या का कारण क्या हो सकता है?

+0

क्या आप अपना कोड पोस्ट कर सकते हैं? – Kuberchaun

उत्तर

9

यहां कुछ कोड है जिसका उपयोग मैंने अपने पीजी डेटाबेस को एक वेब इंटरफ़ेस देने का प्रयास करने के लिए किया था। यह कर्ल या वेब ब्राउजर के माध्यम से आप जो आदेश भेजते हैं उसके आधार पर रिकॉर्ड्स को कनेक्ट और डालने/हटाने/चुनने में सक्षम है।

var app = require('express').createServer(); 
var pg = require('pg'); 
var conString = "postgres://YOURUSER:[email protected]/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'); 
}); 
संबंधित मुद्दे