安装Express.js后,我在节点上写了以下内容:
var express = require('express'), app =express.createServer();
app.configure(function(){
app.use(express.methodOverride());
app.use(express.bodyParser());
app.use(express.router);
});
app.get('/', function(req, res){
res.send('hola mundo');
});
app.listen(3020);
console.log('Hola Mundo');
当我启动应用程序时,我可以看到“你好,世界”的信息,但当我提交请愿书时,我收到了这个:
TypeError: Object #<IncomingMessage> has no method 'call'
at Object.router [as handle] (/home/alumno/Escritorio/nodejs/node_modules/express/node_modules/connect/lib/middleware/router.js:96:6)
at next (/home/alumno/Escritorio/nodejs/node_modules/express/node_modules/connect/lib/http.js:203:15)
at Object.bodyParser [as handle] (/home/alumno/Escritorio/nodejs/node_modules/express/node_modules/connect/lib/middleware/bodyParser.js:88:61)
at next (/home/alumno/Escritorio/nodejs/node_modules/express/node_modules/connect/lib/http.js:203:15)
at Object.methodOverride [as handle] (/home/alumno/Escritorio/nodejs/node_modules/express/node_modules/connect/lib/middleware/methodOverride.js:35:5)
at next (/home/alumno/Escritorio/nodejs/node_modules/express/node_modules/connect/lib/http.js:203:15)
at Object.handle (/home/alumno/Escritorio/nodejs/node_modules/express/lib/http.js:84:5)
at next (/home/alumno/Escritorio/nodejs/node_modules/express/node_modules/connect/lib/http.js:203:15)
at HTTPServer.handle (/home/alumno/Escritorio/nodejs/node_modules/express/node_modules/connect/lib/http.js:216:3)
at HTTPServer.emit (events.js:70:17)
感谢阅读
3条答案
按热度按时间szqfcxe21#
删除
app.use(express.router)
,它的工作完美。jqjz2hbq2#
出现该错误是因为使用的是
express.router
而不是app.router
。t2a7ltrp3#
尝试使用express-validator模块。可以找到here
像这样