Why does req.body come back as undefined in Express?
Because express.json() was not added or was added after the routes that read req.body. Add app.use(express.json()) before any route that needs to parse JSON request bodies.
Verify This Answer
Cross-check this information using these trusted sources:
More FAQs in Common Express Server Setup Mistakes (and How to Fix Them)
Body parser missing or after routes, no error handler, hardcoded port, CORS misconfigured, .env not loaded, routers not mounted, handlers that forget to respond, misuse of next, sync heavy work in handlers, and console.log in production.
Routers need to be mounted in app.js with app.use('/path', router). Creating a router in routes/auth.js is not enough; you must attach it to the Express app.
Your handler did the work but forgot to send a response. Every handler must call res.send, res.json, or res.end. Better: use a wrapper that catches errors and sends a response automatically.
Still have questions?
Browse all our FAQs or reach out to our support team
