7
私はNPMを使用して「Expressのインストールされている、私は3000でリスニングポート番号を首尾よく持っているが、しばらくした後、私は次のエラーを得た、"TypeError:res.sendStatusは関数ではありません"なぜいつこのエラーが発生するのですか?
TypeError: res.sendStatus is not a function
私たちが知っているように、res.sendStatus(404)
はexpress.butに関連します明示されています。ここで
は、ソースコードはここに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のバージョンを確認してください。 '4.x'だけが' res.sendStatus'を使います。 –
固定!ありがとう@PatrickRoberts私は "package.json"ファイルで定義されたエクスプレスバージョンが3.x(今更新されました)であることを発見しましたが、エクスプレスバージョン4.13.4をグローバルにインストールしました。それは常に4.xのバージョンを返すので、私はバージョンについてあまり心配していませんでした。 –
Expressはグローバルにインストールされているはずではありませんので、実行しないでください。 –