I am getting the following exception :
throw er; // Unhandled 'error' event
^
Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client
at validateHeader (_http_outgoing.js:503:11)
at ServerResponse.setHeader (_http_outgoing.js:510:3)
at ServerResponse.header (/Users/athulmuralidharan/my_documents/MS/MSD/projects/MLL-backEnd/node_modules/express/lib/response.js:730:10)
at ServerResponse.send (/Users/athulmuralidharan/my_documents/MS/MSD/projects/MLL-backEnd/node_modules/express/lib/response.js:170:12)
at ServerResponse.json (/Users/athulmuralidharan/my_documents/MS/MSD/projects/MLL-backEnd/node_modules/express/lib/response.js:256:15)
at /Users/athulmuralidharan/my_documents/MS/MSD/projects/MLL-backEnd/controllers/users.js:56:13
at model.Query.<anonymous> (/Users/athulmuralidharan/my_documents/MS/MSD/projects/MLL-backEnd/node_modules/mongoose/lib/model.js:3928:16)
at /Users/athulmuralidharan/my_documents/MS/MSD/projects/MLL-backEnd/node_modules/kareem/index.js:297:21
at /Users/athulmuralidharan/my_documents/MS/MSD/projects/MLL-backEnd/node_modules/kareem/index.js:135:16
at process._tickCallback (internal/process/next_tick.js:150:11)
Intention : To verify if the returned object is null Code:
exports.login = function(req, res,next) {
console.log
User.findOne({email: req.body.username,password: req.body.password}, function(err,obj)
{
if (err)
res.send(err);
if (obj == null)
{
console.log("null returned");
res.status(404).send("Oh uh, something went wrong");
}
console.log(obj);
res.json(obj);
}
);