Can't set headers after they are sent on express
You're sending a response twice via res.end()
. Get rid of the second one and you should be fine. Also, calling res.end()
after res.render()
is redundant since res.render()
automatically ends the response with the rendered result by default.
Just learned this! pass your responses through a function that checks if the response was already sent:
app.use(function(req,res,next){ var _send = res.send; var sent = false; res.send = function(data){ if(sent) return; _send.bind(res)(data); sent = true;}; next();});