简体   繁体   English

“TypeError:res.sendStatus不是函数”为什么我会在一段时间后收到此错误?

[英]“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.

相关问题 TypeError: res.sendStatus is not a function - 为什么我一直收到这个错误? - TypeError: res.sendStatus is not a function - Why do I keep getting this error? node-express 错误:表示已弃用 res.send(status):请改用 res.sendStatus(status) - node-express error : express deprecated res.send(status): Use res.sendStatus(status) instead 为什么我收到错误类型错误:“xyz”不是 function? - Why am I getting ERROR TypeError: “xyz” is not a function? 为什么我收到TypeError X不是函数 - Why am I getting TypeError X is not a function 为什么会出现“未捕获的TypeError”错误? - Why am I getting 'Uncaught TypeError' error? 为什么我会收到这个错误:Uncaught TypeError: this.createLink is not a function at new Link at<anonymous> 1:9? - Why am I getting this error: Uncaught TypeError: this.createLink is not a function at new Link at <anonymous>1:9? 我收到此错误:“TypeError:回调不是函数”,但 function 仍在执行 - I am getting this error: 'TypeError: callback is not a function', but the function is still executing 为什么我收到错误“Uncaught TypeError: st.replace is not a function” - Why am I getting the error "Uncaught TypeError: st.replace is not a function" 为什么我收到错误:TypeError:“_co.form.submit 不是函数”? - Why am I getting error: TypeError: “_co.form.submit is not a function”? 为什么我得到 TypeError: _this.props.&quot;functionName&quot; is not a function ReactJS - Why am I getting TypeError: _this.props."functionName" is not a function ReactJS
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM