2016-06-19 5 views
0

私はserver.js(ここではappは明示的なインスタンス)に次のコードを持っています。これはserver.jsと同じディレクトリにあるindex.htmlというファイルを返します。sendFileはエクスプレスベースのNodeアプリの関数ではありませんか?

app.get('/', function (req, res) { 
    var indexPath = path.resolve('index.html'); 
    res.sendFile(indexPath); 
}); 

ログアウトindexPathこれは私のhtmlファイルへの正しいパスです。しかし、私は次のエラー

TypeError: res.sendFile is not a function

を取得し、トレースを呼び出す:エクスプレス、senfile、ないsendFileにするために使用する方法の古いバージョンでは

at Object.handle (/Users/alexanderbollbach/Desktop/ABApp/server.js:54:9) 
at next_layer (/Users/alexanderbollbach/Desktop/ABApp/node_modules/express/lib/router/route.js:103:13) 
at Route.dispatch (/Users/alexanderbollbach/Desktop/ABApp/node_modules/express/lib/router/route.js:107:5) 
at /Users/alexanderbollbach/Desktop/ABApp/node_modules/express/lib/router/index.js:195:24 
at Function.proto.process_params (/Users/alexanderbollbach/Desktop/ABApp/node_modules/express/lib/router/index.js:251:12) 
at next (/Users/alexanderbollbach/Desktop/ABApp/node_modules/express/lib/router/index.js:189:19) 
at Layer.jsonParser [as handle] (/Users/alexanderbollbach/Desktop/ABApp/node_modules/body-parser/index.js:31:38) 
at trim_prefix (/Users/alexanderbollbach/Desktop/ABApp/node_modules/express/lib/router/index.js:226:17) 
at /Users/alexanderbollbach/Desktop/ABApp/node_modules/express/lib/router/index.js:198:9 
at Function.proto.process_params (/Users/alexanderbollbach/Desktop/ABApp/node_modules/express/lib/router/index.js:251:12) 
+0

使用しているExpressのバージョンは何ですか? – elclanrs

+0

私は使用しているバージョン^ 4 –

+0

正確なバージョンは? 'sendFile'は4.8.0+でのみ利用可能です – elclanrs

答えて

2

を。

Express 4.14に更新すると、sendFileを使用できるようになります。 4.14もセキュリティ更新プログラムですので、お勧めします。

package.jsonファイルにこれを追加できます。"express": "^4.14.0"

関連する問題