`express.js`发送静态文件时抛出错误
我使用的是express版本:`express.js`发送静态文件时抛出错误,express,Express,我使用的是express版本:express@4.12.3 在提供静态html时,我使用以下内容: app .get('*', function (req, res) { res.sendFile('public/main.html'); }) 但我得到的错误是: TypeError: path must be absolute or specify root to res.sendFile 相反,如果我使用res.sendfile-工作正常,但是cmd告诉
express@4.12.3
在提供静态html时,我使用以下内容:
app
.get('*', function (req, res) {
res.sendFile('public/main.html');
})
但我得到的错误是:
TypeError: path must be absolute or specify root to res.sendFile
相反,如果我使用res.sendfile
-工作正常,但是cmd
告诉我使用sendfile
-我还能做什么?这里的问题是什么
有人能给我指路吗?试试这个,不要写相对路径:
res.sendFile(__dirname +'/public/main.html');
可能重复的