Node.js 및 Express에 큰 문제가 있습니다.Express bodyParser
내 요청의 본문 요소를 사용하고 싶지만 내 프로그램에서 bodyParser()
을 사용하는 방법을 모른다.
requestServer = function(){
var express = require('express');
this.ex = express;
//this.app = require('express')();
this.app = express();
this.server = require('http').createServer(this.app);
this.io = require('socket.io').listen(this.server, {log: false});
this.socket = [];
this.app.post('/test/', this.testFunction.bind(this));
this.io.sockets.on('connection', this.socketConnection.bind(this));
this.app.use(express.bodyParser());
};
...
requestServer.prototype.positionChange = function(req, res){
console.log(req.body); // says its undefined???
console.log(req.body.name); // also undefined :(
};
...
var server = new requestServer();
server.listen(6667);
을 내가 잘못 뭐하는 거지 : 그것은 자신을 위해보기 ... 단지 app.use()
아니다? 응용 프로그램이 반환되는 표현 객체이기 때문에
어디서'positionChange'가 호출 되었습니까? – Prinzhorn
'this'를 사용하는 이유가 무엇입니까? 조금 비 관습. –
연결 청취를 시작하기 전에'app.use (express.bodyParser()); '를 이동하려 했습니까? – TheHippo