安装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');
我可以看到消息" 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)
感谢您阅读
答案 0 :(得分:2)
删除app.use(express.router),效果很好。
答案 1 :(得分:1)
您收到该错误是因为您使用的是express.router
而非app.router
。
答案 2 :(得分:0)
尝试使用express-validator模块。可以被找寻到 here
像这样 var expressValidator = require('express-validator');
app.use(expressValidator());