node.js - 错误:ENOENT:没有这样的文件或目录 index.html Node.js
问题描述
尝试从 node.js 重定向路由以响应路由器时出现问题。
app.get('*', (req,res) => {
res.sendFile(path.resolve(__dirname + '../client/build/index.html'));
});html
我的浏览器说:
Error: ENOENT: no such file or directory, stat '/home/node/app../client/build/index.html'
顺便说一句,__dirname 是做什么的?
解决方案
你应该使用这样的东西......
path.resolve(__dirname, '../', 'client/build/index.html')
**Like Explained here**
path.resolve('wwwroot', 'static_files/png/', '../gif/image.gif');
{
if the current working directory is /home/myself/node,
this returns '/home/myself/node/wwwroot/static_files/gif/image.gif'
}
推荐阅读
- r - 包创建中的 dplyr:group_by 带字符串,不带 group_by_
- mysql - 将字符串转换为时间 sql 或雪花
- php - 使用try catch时如何隐藏PHP错误
- c++ - “class CLASS_EXPORT IKLogin_Export”是什么意思
- php - 如何使用 CodeIgniter DB Forge 生成 createdAt 和 updatedAt 时间戳/日期时间?
- python - Python:ValueError:无法反序列化关键数据
- javascript - 引导轮播滑块活动类和下一个/上一个按钮不起作用
- javascript - buttonImage 中没有显示图像,这是我的日期选择器日历图标的 JS 小部件
- javascript - 这是 C# ASP.NET 通用处理程序冗余变量中的主要错误吗?
- python - 如何将列表(StringType)的元素相互添加