【发布时间】:2019-05-26 16:12:48
【问题描述】:
我有一个这样的目录结构:
server
code
app.js
web
html
index.html
css
index.css
scripts
index.js
我的 app.js 代码正在尝试提供 html 文件 index.html 但显示错误 这是代码:
app.get('/web',function(req,res)
{
res.sendFile('../web/html/index.html');
})
传递给 sendFile() 的路径并使其正常工作,以便 html 文件在运行时也能找到脚本文件和 css ?
我是 node.js 的新手。
【问题讨论】:
-
试试
res.sendFile('./web/html/index.html') -
@Jhecht 我试过你的答案,但我得到以下输出:> TypeError: path must be absolute or specified root to res.sendFile
-
然后试试
res.sendFile('./web/html/index.html', { root : __dirname })
标签: javascript html node.js web backend