I am making template using express and ejs, res,end(). But didn't find any solution. I have tried my many things, like next()
Below is my code:
app.get('/', function (req, res, next) {
pool.getConnection(function(err, connection) {
// Use the connection
connection.query( 'SELECT * FROM wp_posts WHERE post_name = "mainlogo"', function(err, mainmenu) {
var data = JSON.stringify(mainmenu);
return res.render('index', {items : data});
res.end();
});
connection.query( 'SELECT * FROM wp_posts WHERE id = 14', function(err, homecontent) {
var dataHome = JSON.stringify(homecontent);
return res.render('index', {homeitem : dataHome});
res.end();
connection.release();
});
});
});
This will give me error:
Error: Can't set headers after they are sent.
Can anyone help me?