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 trialDennis Klarenbeek
17,168 PointsRoute in Epxress won't react as expect, can somebody verify my code?
Hi,
I'm working on a web application and I made together with the Teamtreehouse videos an API with Express and Mongoose. With this step I've made a Parent-Child structure (Location-documents) To explain: One location (with information) can have three types of documents. In these documents there is stored al lot of information but also 3 different one: cameras, monitors and pw. This one are objects which I need the possibility to get, post, put and delete them. At the moment I have the following code and I get the response message:
{
"error": {
"message": "Cannot read property 'push' of undefined"
}
}
post route for the camera
router.post("/:lID/documents/:dID/cameras", function(req, res, next) {
req.location.documents.cameras.push(req.body);
req.location.documents.save(function(err, camera){
if(err) return next(err);
res.status(201);
res.json(camera);
});
});
Can somebody help me with this one?