如果我做一个
res.sendfile('public/index1.html');
然后我收到服务器控制台警告
表达已弃用
res.sendfile:res.sendFile改为使用
但它在客户端工作正常。
但是当我将其更改为
res.sendFile('public/index1.html');
我得到一个错误
TypeError:路径必须是绝对路径或将根目录指定为
res.sendFile
并且index1.html不呈现。
我无法弄清楚绝对路径是什么。我的public目录与处于同一级别server.js。我正在res.sendFile使用server.js。我也宣布app.use(express.static(path.join(__dirname, 'public')));
添加我的目录结构:
/Users/sj/test/
....app/
........models/
....public/
........index1.html
在此处指定的绝对路径是什么?
我正在使用Express4.x。
res.sendFile从内部打电话app.get('/', function(req, res){res.sendFile("...")})按需发送。
express.static中间件来服务您的公共目录,为什么需要res.sendFile发送public/index1.html?