Skip to content
RED SAG Skills
easyStudy question · answer published in Node.js interview questions, so no pointshttpnodejsdebugging

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

Discussion 0

Join free to post in the discussion.

Related questions