NodeJS Express.js:对象#< IncomingMessage>没有方法“call”

vlju58qv  于 2022-12-18  发布在  Node.js
关注(0)|答案(3)|浏览(174)

安装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)

感谢阅读

szqfcxe2

szqfcxe21#

删除app.use(express.router),它的工作完美。

jqjz2hbq

jqjz2hbq2#

出现该错误是因为使用的是express.router而不是app.router

t2a7ltrp

t2a7ltrp3#

尝试使用express-validator模块。可以找到here
像这样

var   expressValidator         = require('express-validator');
 app.use(expressValidator());

相关问题