0
var express = require('express'); // Express instance to access its
var path = require('path');
var mongoose = require("mongoose"); // mongodb ODM
var bodyParser = require('body-parser');
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
app.set('port', process.env.PORT || 3000); //
app.use(express.static(path.join(__dirname, 'node_modules')));
mongoose.connect(config.MONGO_DB_URI, function(error){
if (error) {
console.log("Oops! Connection Failed! " + error);
} else {
console.log("Ahoy! Connection Successful with Mongo!");
}
});
app.use('/api', function(req, res){
console.log("dasasasa");
console.log(req.body);
});
module.exports = app;
ログすると、req.body
は空のオブジェクトです{}。 また、ボディパーサーのバージョンは次のとおりです。nodejs body-parserがデータを取得できません
npm body-parser -v
2.15.9
私はここで何が不足してすることができますか?
また、私は郵便配達員と一緒に試しています。
は、あなたがあなたの要求データを設定し、絶対によろしいです郵便配達員で正しく? – Lazyexpert
ねえ、私はx-ww.form-urlencodedを作ったときにうまくいった –