Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

DELETE Method Hanging

This isn't so much a question as a note to others who may run into the same issue i had.

When testing the Delete method the process would hang and not give a response, after some digging it turned out to be that the mongoose .remove method was missing an argument.

router.delete("/:qID/answers/:aID", function(req,res){
    req.answer.remove(function (err){
        req.question.save(function(err,question){
            if(err){
                return next(err);
            }
            res.json(question);
        });
    });
});

line of code needed to become.

router.delete("/:qID/answers/:aID", function(req,res){
    req.answer.remove(req.params.aID,function (err){
        req.question.save(function(err,question){
            if(err){
                return next(err);
            }
            res.json(question);
        });
    });
});

1 Answer

This was my solution, i hope it helps others. But still i wonder if i might have missed something somewhere that made it work without my change.