I am using Express Router
as shown below
router.post('/do', function(req, res, next) {
// some sample code
var questions = new Questions();
questions.display(req, res);
});
The display
function takes care of calling res.send
.
In above snippet I am creating instance of Questions
and passing req, res
objects to it.
Now from my sample.js
file I am firing almost 5 ajax requests to this same route and only one request is succeeding and after that I am getting error
Can't set headers after they are sent.
So I am not sure why I am getting this error!.
Can anybody help ?
UPDATE
Code in display function
Questions.prototype.display = function(req, res) {
// Check if type of question exists
if (req.body.questionType) {
res.send({message: 'No Type found in request body!'});
} else {
// logic for getting questions from DB based on question type
return res.send(questions);
}
}