Monday 13 March 2017

Error when trying to fetch data from mongodb: Can't set headers after they are sent

Pretty new to node/express.I'm checking to see if the JOB(via the JOBID) already exists in the database IF YES SHOW IT IN VIEW PAGE I am trying to fetch data from mongodb to HTML vie page via Nodejs,Express Router and Controller.I guess the problem is with router page i am not sure how to pass data from node to router and from router to controller. I have JOBID I need to fetch all the detail corresponding to that job ID and show it in a view page. Please help me on this i am very new to MEAN Stack

Router Code:
                router.post('/RequirementView',function(req,res)
                {
                    addRequirement.requirementView(req,res);
                    res.send(res.requirement);

                });


NodeJS Code:      
            exports.requirementView = function (req, res) {
               if(req.body.JobID)
               {
                   RequirementModel.findOne({ 'JobID' :  req.body.JobID}, function(err, requirement) {
                       if(requirement!=null)
                       {                    
                           requirement.Vertical=req.body.Vertical || requirement.Vertical ;                  
                           requirement.save(function(err) {
                           res.status(200).send(requirement);
                           });



via Saranya Rajan

No comments:

Post a Comment