Express.js req.body undefined

前端 未结 30 2764
半阙折子戏
半阙折子戏 2020-11-22 12:02

I have this as configuration of my Express server

app.use(app.router); 
app.use(express.cookieParser());
app.use(express.session({ secret: \"keyboard cat\" }         


        
30条回答
  •  天涯浪人
    2020-11-22 12:32

    First make sure , you have installed npm module named 'body-parser' by calling :

    npm install body-parser --save
    

    Then make sure you have included following lines before calling routes

    var express = require('express');
    var bodyParser = require('body-parser');
    var app = express();
    
    app.use(bodyParser.json());
    

提交回复
热议问题