最佳答案
如果我做一个
res.sendfile('public/index1.html');
然后我得到一个服务器控制台警告
表达不赞成的
res.sendfile: 使用res.sendFile代替
但是它在客户端运行良好。
但是当我把它改成
res.sendFile('public/index1.html');
我得到一个错误
TypeError: 路径必须是绝对的或者指定根到
res.sendFile
并且不呈现 index1.html。
我不能算出绝对路径是什么。我有与 server.js相同级别的 public目录。我在用 server.js做 res.sendFile。我还声明了 app.use(express.static(path.join(__dirname, 'public')));
添加我的目录结构:
/Users/sj/test/
....app/
........models/
....public/
........index1.html
这里要指定的绝对路径是什么?
我用的是 Express 4. x。