我想呈現一個index.html,但我得到錯誤enoent,即使有正確的路徑。Node.js - res.sendFile - 錯誤:ENOENT,但路徑正確
//folders tree
test/server.js
test/app/routes.js
test/public/views/index.html
//routes.js
app.get('*', function(req, res) {
res.sendFile('views/index.html');
});
//server.js
app.use(express.static(__dirname + '/public'));
require('./app/routes')(app);
我也試過
res.sendFile(__dirname + '/public/views/index.html');
如果我使用
res.sendfile('./public/views/index.html');
然後它的工作原理,但我看到上面寫着的sendfile已被棄用警告,我不得不使用SENDFILE。
什麼時候會發生什麼你的'console.log'是你放入'sendFile'的路徑嗎?你有沒有得到你期望的道路? – Aurora0001
它給了我路徑'/Users/me/Desktop/test/app/public/views/index.html',它應該是正確的路徑 – Alex
然後你可以包含** complete **錯誤信息嗎?看起來很奇怪,路徑是正確的,但它仍然不起作用。 – Aurora0001