javascript - What could be the reason for Error: Can't set headers after they are sent -
hi getting below error
error: can't set headers after sent. @ serverresponse.outgoingmessage.setheader (_http_outgoing.js:331:11) @ serverresponse.header (/users/rajesh/documents/nodeproject/nodetest1/node_modules/express/lib/response.js:662:10) @ serverresponse.send (/users/rajesh/documents/nodeproject/nodetest1/node_modules/express/lib/response.js:146:12) @ fn (/users/rajesh/documents/nodeproject/nodetest1/node_modules/express/lib/response.js:896:10) @ view.exports.renderfile [as engine] (/users/rajesh/documents/nodeproject/nodetest1/node_modules/jade/lib/jade.js:325:12) @ view.render (/users/rajesh/documents/nodeproject/nodetest1/node_modules/express/lib/view.js:76:8) @ function.app.render (/users/rajesh/documents/nodeproject/nodetest1/node_modules/express/lib/application.js:527:10) @ serverresponse.res.render (/users/rajesh/documents/nodeproject/nodetest1/node_modules/express/lib/response.js:900:7) @ /users/rajesh/documents/nodeproject/nodetest1/app.js:57:9 @ layer.handle_error (/users/rajesh/documents/nodeproject/nodetest1/node_modules/express/lib/router/layer.js:58:5)
could 1 tell me reason it.my code
router.post('/readcsvfile',function(req,res){ if(typeof req.files.filecsv === 'undefined'){ var err = {message: 'please select csv file'}; res.render('error', {message: err.message,error: err}); } var reader = yacsv.createcsvfilereader(req.files.filecsv.path,{ 'separator':',', 'quote':'"', 'escape':'"' }); reader.addlistener('data',function(data){ var json = createjsonobject(data); _data.push(json); }); reader.addlistener('error',function(err){ console.error("err.status " + err.status); //err.status = 500; //res.status(500); err.message = 'select proper csv file'; res.render('error', {message: err.message,error: err}); console.error(util.inspect(err)); }); reader.addlistener('end', function() { res.render('rendercsv',{data: _data}); }); var _data = [];
});
add "return" statement after each "res.render" command.
Comments
Post a Comment