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
})Discussion 0
Join free to post in the discussion.
Related questions
- Status code after creating a resourceFull Stack Developer
- Fixing a CORS errorFull Stack Developer
- Which method is idempotentFull Stack Developer
- Status 401 vs 403Full Stack Developer
- PATCH vs PUT for one fieldFull Stack Developer
- Comparing a column to NULLFull Stack Developer
- Posts vanish from GET linksFull Stack Developer
- What triggers a preflightFull Stack Developer