Skip to content
RED SAGSkills
easy5 pts · first answer countshttpnodejsdebugging

Empty req.body in Express

The server uses express.json(), but req.body is empty when this request arrives. What is the simplest fix on the client?

await fetch('/api/todos', {
  method: 'POST',
  body: JSON.stringify({ title: 'Buy milk' }),
})

// server
app.use(express.json())
app.post('/api/todos', (req, res) => {
  console.log(req.body) // empty, no title
})
Choose one answer