[英]“TypeError: res.sendStatus is not a function” why I am getting this error after sometime?
I have installed 'express' using npm, I've successfully got port number listening on 3000. but after a while i got the following error, 我已经使用npm安装了'express',我已经成功地在3000上收听了端口号。但过了一段时间我得到了以下错误,
TypeError: res.sendStatus is not a function TypeError:res.sendStatus不是函数
As we know, res.sendStatus(404)
is related to express.but express is clearly located. 我们知道, res.sendStatus(404)
与express有关。但express是明确定位的。
Here is source code in app.js 这是app.js中的源代码
var express = require('express'),
app = express();
app.get('/', function(req, res){
res.send('Hello Worlds');
});
app.use(function(req, res){
res.sendStatus(404);
});
var server = app.listen(3000, function() {
var port = server.address().port;
console.log('Express server listening on port %s', port);
});
Here is my full cmd output, 这是我的完整cmd输出,
> $ node app.js
Express server listening on port 3000
TypeError: res.sendStatus is not a function
at Object.handle (I:\mongoUniversity\hello_world_templates\app.js:14:9)
at next (I:\mongoUniversity\hello_world_templates\node_modules\connect\lib\proto.js:174:15)
at pass (I:\mongoUniversity\hello_world_templates\node_modules\express\lib\router\index.js:110:24)
at Router._dispatch (I:\mongoUniversity\hello_world_templates\node_modules\express\lib\router\index.js:173:5)
at Object.router (I:\mongoUniversity\hello_world_templates\node_modules\express\lib\router\index.js:33:10)
at next (I:\mongoUniversity\hello_world_templates\node_modules\connect\lib\proto.js:174:15)
at Object.expressInit [as handle] (I:\mongoUniversity\hello_world_templates\node_modules\express\lib\middleware.js:30:5)
at next (I:\mongoUniversity\hello_world_templates\node_modules\connect\lib\proto.js:174:15)
at Object.query [as handle] (I:\mongoUniversity\hello_world_templates\node_modules\connect\lib\middleware\query.js:43:5)
at next (I:\mongoUniversity\hello_world_templates\node_modules\connect\lib\proto.js:174:15)
at Function.app.handle (I:\mongoUniversity\hello_world_templates\node_modules\connect\lib\proto.js:182:3)
at Server.app (I:\mongoUniversity\hello_world_templates\node_modules\connect\lib\connect.js:67:37)
at emitTwo (events.js:87:13)
at Server.emit (events.js:172:7)
at HTTPParser.parserOnIncoming [as onIncoming] (_http_server.js:525:12)
at HTTPParser.parserOnHeadersComplete (_http_common.js:88:23)
I have checked similar questions, where they told to check if 'express' was installed or not, but i have installed it correctly. 我已经检查了类似的问题,他们告诉我们检查是否安装了'express',但我已经正确安装了它。 Then what am i doing wrong? 那我在做错什么?
使用express 4.x
,因为只有新的express API支持res.sendStatus
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.