Sudden failure of express body-parser middleware?

problem description

recently, middleware (body-parser) in express suddenly fails, req.body can not get any value , req.query can get the value . It was useful to add body-parser middleware at first, until yesterday when token was added, body-parser failed. Try to get rid of token, it is useless, it is not this problem, it is also said that the version is not right, the introduction of middleware, or useless!

related codes

 const bodyParser = require("body-parser");
 app.use(bodyParser.json());

solve the problem by yourself. Set Content-Type in the request header to application/json .

headers: {
    'Content-Type': 'application/json'
}

in addition, req.body cannot accept any parameters for a direct request in postman .
solution: request: check raw in the request body, and set the format to JSON (application/json) .

Menu