0
저는 nodejs를 처음 사용하며 js를 표현합니다. 우편 노드를 사용하여 nodejs 앱에 json 객체를 보내려고합니다. PFB 내 응용 프로그램 코드req.body.data가 expressjs에서 정의되지 않았습니다.
var express = require("express");
var bodyParser = require('body-parser');
var app = express();
app.use(bodyParser.json());
app.post("/game",function(req,res){
console.log(req.body);
console.log(req.body.gameId);
//var body = req.body;
//game.addGame(req,res,body);
});
app.listen(setting.port);
console.log(`The app is listening to port ${setting.port}`);
나는
{
"gameID": 4,
"gameLevel": 3,
"gameImage": "/3wewe/wewrw",
"gameName": "Game2",
"waitTimeForWinny": 30,
"totalTime": 31,
"orderSequence": 1,
"maxPoints": 10
}
가 그럼 난 콘솔에서 아래의 출력을 가지고 우체부 사용하여 아래의 JSON 개체를 보낼 수 있습니다.
{ gameID: 4,
gameLevel: 3,
gameImage: '/3wewe/wewrw',
gameName: 'Game2',
waitTimeForWinny: 30,
totalTime: 31,
orderSequence: 1,
maxPoints: 10 }
undefined
json 개체가 req.body에 들어 있습니다. 하지만 req.body.gameId를 사용하여 필드를 추출 할 수 없습니다.
이 문제를 해결하는 방법을 알려주십시오.
고마워요 (소문자
d
주의)gameId
를 기록하고 있습니다 ... 좋은 IDE에 대한이있다 그런 작은 문제에 시간을 낭비 할 필요가 없도록 nodejs. –저는 JetBrains [WebStorm] (https://www.jetbrains.com/webstorm/) (스폰서 링크가 아님, 저에게 돈을 주어야 함)를 선호합니다. 더 이상 모든 JS/TS 개발자 작업에 사용합니다. –