To set up my bodyparser I use the following code:
const express = require('express')
const app = express();
const bodyParser = require('body-parser');
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({
extended: false
}));
Now if I have the following POST route in my express router:
var router = require('express').Router();
router.post('/sendadvertisement', async (req, res) => {
console.log(req.body)
});
The result is [Object: null prototype] {advertisement: 'test'}
-> My req.body
isn't empty because it's in json format in my console output.
I don't really understand how this result can happen because I defined that the body should be in json format.
I also tried it with app.use(express.json())
, doesn't work either.