错误:ENOENT:没有这样的文件或目录index.html Node.js

时间:2018-06-06 11:32:11

标签: node.js reactjs express

尝试将路由从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'

Here's printscreen of my directories

顺便问一下,__ dirname是做什么的?

1 个答案:

答案 0 :(得分:1)

你应该使用这样的东西......

  

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'
}