1
我想在nodejs中加載HTML文件。在公共文件夾中,我有兩個html文件test.html和index.html。我想用nodejs來展示這些頁面,但是它爲index.html工作,並且在測試的情況下,它顯示一個錯誤,說res.sendFile不是一個函數。在Nodejs中加載HTML文件
var express = require('express');
var app = express();
var path = require('path');
// viewed at http://localhost:8080
app.get('/', function(req, res) {
res.sendFile(path.join(__dirname + '/public/index.html'));
});
// viewed at http://localhost:8080
app.get('/test', function(req, res) {
res.sendFile(path.join(__dirname + '/public/test.html'));
});
app.listen(8080);
加急4 http://stackoverflow.com/questions/10434001/static-files-with-express-js#10440149 – cyberwombat
的代碼工作正常,當我運行它。我無法重現這個問題。 – Quentin
謝謝!看起來我使用的是過時的包 – user3001937