我对 Node.js 和 Express 有一个大问题。
我想使用我的请求的正文元素,但我不知道如何bodyParser()
在我的程序中使用;这不仅仅是app.use()
...
你自己看:
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);
我究竟做错了什么?