3
私は実際にExpressでnode.jsに非常に小さなアプリケーションを持っていますが、req.bodyにアクセスすることはできません。ミドルウェア内のreq.bodyにアクセスできない
これは私のapp.js
コードです:
var express = require('express'),
middleware = require('./middleware'),
mysql = require('mysql'),
app = express();
app.use(middleware.authenticate);
app.use(middleware.getScope);
app.listen(3000);
module.exports = app;
そしてミドルウェアを使用してファイル:すべてのケースで
var bcrypt = require('bcrypt'),
mysql = require('mysql');
function authenticate(req, res, next){
console.log(req.body);
next();
}
function getScope(req, res, next){
console.log(req.body);
next();
}
module.exports.authenticate = authenticate;
module.exports.getScope = getScope;
はreq.body undefined
です。
私はデータを送信していますx-www-form-urlencoded
プロトコルで郵便配達員、この場合は必須です。
感謝!!あなたが表現するbody-parser
を追加する必要が
をあなたは[ '体を必要とします-parser'](https://github.com/expressjs/body-parser)モジュールをインストールします。 –