ENOENT,打开“/app/public/index.html”nodejs

我正在使用heroku来托pipenodejs应用程序。 我推文件树名称test像这样:

 -test /-server.js /-Procfile /-package.json /-public /-index.html /-style.css /script.js 

我的server.js文件我处理这样的请求:

 fa.readFile(__dirname + '/public/index.html', function(error, data) { if (error) { res.writeHead(500, {'Content-type':'text/plain'}); res.end(error); } else { res.writeHead(200, {'Content-type':'text/html'}); res.end(data); } }); 

当我testing的东西,它想出了这个: ENOENT, open '/app/public/index.html'我不知道为什么它指的是/app文件夹。 我在本地testing它,它返回纯CSS页面没有CSS和JS。

您需要将项目结构向下移动一个级别。

您应该将test目录的内容作为您的应用程序推送,而不是应用程序的test目录的回购站。

 -server.js -Procfile -package.json -public /-index.html /-style.css /script.js