node.js - Can't set headers after they are sent in Express using Node -


i making template using express , ejs, res,end(). didn't find solution. have tried many things, next()

below code:

app.get('/', function (req, res, next) { pool.getconnection(function(err, connection) {   // use connection   connection.query( 'select * wp_posts post_name = "mainlogo"', function(err, mainmenu) {     var data = json.stringify(mainmenu);     return res.render('index', {items : data});    res.end();    });    connection.query( 'select * wp_posts id = 14', function(err, homecontent) {     var datahome = json.stringify(homecontent);     return res.render('index', {homeitem : datahome});    res.end();     connection.release();   }); });  }); 

this give me error:

error: can't set headers after sent. 

can me?

each query trying send full response browser second 1 fails. try this:

app.get('/', function (req, res, next) {   pool.getconnection(function(err, connection) {     // use connection     connection.query( 'select * wp_posts post_name = "mainlogo"', function(err, mainmenu) {       //got results of first query       var posts = json.stringify(mainmenu);        connection.query( 'select * wp_posts id = 14', function(err, homecontent) {         //got results of second query         var datahome = json.stringify(homecontent);         //return both         return res.render('index', {homeitem : datahome, items : data});         //close connection         res.end();         //release connection         connection.release();       });   });   }); 

Comments

Popular posts from this blog

javascript - Bootstrap Popover: iOS Safari strange behaviour -

Magento/PHP - Get phones on all members in a customer group -

session - Logging Out Using PHP -