“types错误:res.sendStatus不是一个函数”为什么我得到这个错误后有一段时间?

我已经使用npm安装了“express”,我已经成功地获得了在3000上监听的端口号。但过了一段时间,我得到了以下错误,

TypeError:res.sendStatus不是一个函数

如我们所知, res.sendStatus(404)与express有关,但express明显位于。

这里是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); }); 

这是我的完整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) 

我检查了类似的问题,他们告诉我们检查是否安装了“express”,但是我已经正确安装了。 那么我做错了什么?

使用express 4.x ,因为只有新的express API支持res.sendStatus