Answer the question
In order to leave comments, you need to log in
Why can't connect to PostgreSQL on node js?
There are controllers in a separate file, the post should display data from the database. displays order-1 and order-2 as needed, but from the database there is an error in the console.
/* POST home page. */
router.post('/', function(req, res, next) {
if (req.body.action === "order-1")
res.send("order-1");
else if(req.body.action === "order-2")
res.send("order-2");
//connect
pg.connect(connect, function(err, client, done) {
if(err) {
return console.log('error fetching client from pool', err);
}
client.query('SELECT * FROM orders', function(err, result) {
if(err) {
return console.error('error running query', err);
}
console.log(result.rows['name']);
done();
});
});
});
var pg = require('pg');
//DB connect
var connect = "postgres://andrey:[email protected]:5432/bytik-life";
var index = require('./routes/index');
Error: Can't set headers after they are sent.
at ServerResponse.OutgoingMessage.setHeader (_http_outgoing.js:356:11)
at ServerResponse.header (C:\Users\artys\Documents\GitHub\boutique-life\node_modules\express\lib\response.js:719:10)
at ServerResponse.send (C:\Users\artys\Documents\GitHub\boutique-life\node_modules\express\lib\response.js:164:12)
at done (C:\Users\artys\Documents\GitHub\boutique-life\node_modules\express\lib\response.js:956:10)
at Object.exports.renderFile (C:\Users\artys\Documents\GitHub\boutique-life\node_modules\jade\lib\index.js:374:12)
at View.exports.__express [as engine] (C:\Users\artys\Documents\GitHub\boutique-life\node_modules\jade\lib\index.js:417:11)
at View.render (C:\Users\artys\Documents\GitHub\boutique-life\node_modules\express\lib\view.js:126:8)
at tryRender (C:\Users\artys\Documents\GitHub\boutique-life\node_modules\express\lib\application.js:639:10)
at EventEmitter.render (C:\Users\artys\Documents\GitHub\boutique-life\node_modules\express\lib\application.js:591:3)
at ServerResponse.render (C:\Users\artys\Documents\GitHub\boutique-life\node_modules\express\lib\response.js:960:7)
"
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question