我在应用程序中使用node
和express
,在网络中使用web server for chrome
从本地文件夹中提供网页。我想通过以下方式将应用程序定向到页面:
app.get('/', function (req, res) {
res.sendFile(path.join(__dirname + '/index.html'));
});
但是它不起作用,并且通过使用console.log()
,将显示以下路径:
D:\node\project10\index.html
您看到的斜杠已更改为反斜杠。也试图通过这种方式解决它:
path.join(__dirname.replace(/\\/g,"/") + '/index.html'))
没有path.join
,问题就解决了,但问题仍然存在。
如何解决?
答案 0 :(得分:1)
当您console.log()path.join()时,它会在另一个方向显示破折号,因为Windows会像这样工作。在浏览器中,破折号是:'/',但在窗口中是相反的。因此问题不在于破折号。