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 trialNathan Boaldin
Courses Plus Student 12,545 PointsWhy does my code not output the 500 reference error message?
Here is my code:
// /questions is /
router.post('/', (req, res)=>{
const o = obj.prop;
res.json({response: 'You sent me a POST request',
body: req.body
});
});
//Catch 404 and forward to error handler
app.use(function(req, res, next) {
const err = new Error('Not Found');
err.status = 404;
next(err);
});
//Error handler
app.use(function(err, req, res, next){
res.status(err.status || 500);
res.json({
error: {
message: err.message
}
});
});
I get this output from postman when I use the route, localhost:3000/questions/
{
"response": "You sent me a GET request"
}