【发布时间】:2016-10-31 21:15:30
【问题描述】:
我的目录是这样设置的:
public
pages
index.html
routers
route.js
在 route.js 中,我执行以下操作:
router.get('/', function(req, res) {
res.sendFile("/public/pages/index.html", {"root": __dirname});
});
我得到 Error: ENOENT: no such file or directory, stat 因为服务器正在查看 myproject/routers/public/pages/index.html 而不是 myproject/public/pages/index.html
1) 我如何解决这个问题并让它使用_dirname 找到正确的路径?
2) 如何让我的服务器记住查看 /public/pages/,这样我就不必每次都指定绝对路径?
【问题讨论】:
标签: javascript node.js rest directory router