Quantcast
Channel: Express.js req.body undefined - Stack Overflow
Viewing all articles
Browse latest Browse all 54

Answer by Marci for Express.js req.body undefined

$
0
0

When I use bodyParser it is marked as deprecated. To avoid this I use the following code with express instead of bodyParser.

Notice: the routes must declared finally this is important! Other answers here described the problem well.

const express = require("express");const app = express();const routes = require('./routes/api');app.use(express.json());app.use(express.urlencoded({ extended: false }));// Routes must declared finallyapp.use('/', routes);

Viewing all articles
Browse latest Browse all 54

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>