Hello!
I am studying the nodejs course, I am in section four, intro to express.
Whenever I do a post request I keep getting the error:
Cannot POST /api/courses - 404
Any idea what I am doing wrong? Im not sure which codeblock to display so here is everything I have for this section.
Hi,
it seems that you forgot to add a "/"
in your app.post so you need to add it => “/api/courses” :
~~~app.post('api/courses', (req, res) => {
const schema = {
name: Joi.string().min(3).required()
}
const result = Joi.validate(request.body, schema);
console.log(result);
if (result.error) {
response.status(400).send(result.error)
return;
}
const course = {
id: courses.length + 1,
name: request.body.name
};
courses.push(course);
response.send(course);
});
1 Like