What could be causing this error to appear?
It seems like the only route available is through post method. I can't seem to find any other place where a header is being sent.
I'm also puzzled as to why body.content is showing up as undefined, even though an object is being sent and the header is set to json. Interestingly, the body parser or app.use(bodyParser.json()) isn't working either.
"express": "^4.17.3"
Your assistance is greatly appreciated
const express = require("express");
const app = express();
app.use(express.json());
app.post("/api/persons/", (req, res) => {
const body = req.body;
//if body has no data return here
console.log(body.content);
if (!body.content) {
return res.status(400).end().json({ error: "missing content" });
}
//generate entry in list
const person = {
number: body.number,
name: body.name,
id: generateID(),
};
persons = persons.concat(person);
res.json(person);
});