I have been following the a scotch.io tutorial to create my first node and angular app. I have seen that relative paths are a common issue online for the Error: ENOENT: no such file or directory
which as far as I can tell is the same as the tutorial so I'm why its not working.
我一直在关注scotch.io教程来创建我的第一个节点和角度应用程序。我已经看到相对路径是错误的在线常见问题:ENOENT:没有这样的文件或目录,据我所知,它与教程相同,所以我就是为什么它不起作用。
The full error message is: Error: ENOENT: no such file or directory, stat'/Users/badman/githubRepos/travelGuide/app/public/index.html' at Error (native)
完整的错误消息是:错误:ENOENT:没有这样的文件或目录,错误(本机)的stat'/ Users / badman / githubRepos / travelGuide / app / public / index.html'
My folder structure is here. My server.js:
我的文件夹结构在这里。我的server.js:
// set up web server
var express = require('express');
var app = express();
var bodyParser = require("body-parser");
// routes
require('./app/routes.js')(app);
// listen (start app with node server.js)
app.listen(3000, function() {
console.log("server going");
})
routes.js:
routes.js:
module.exports = function (app) {
app.get('*', function (req, res) {
res.sendFile(__dirname + '/public/index.html'); // load the single view file (angular will handle the page changes on the front-end)
});
};
Any help is appreciated :)
任何帮助表示赞赏:)
1 个解决方案
#1
3
I had the same problem and I moved
我有同样的问题,我感动了
app.get('*', function (req, res) {
res.sendFile(__dirname + '/public/index.html'); // load the single view file (angular will handle the page changes on the front-end)
});
to server.js right under the require('./app/routes.js')(app);
and that fixed it! Because it was looking for index.html in the wrong place when a server-side route was being called. I think you could have also changed the path too but I found this to be clearer.
在require('。/ app / routes.js')(app)下面的server.js;并修复它!因为它在调用服务器端路由时在错误的位置寻找index.html。我想你也可以改变路径,但我发现这更清楚了。
#1
3
I had the same problem and I moved
我有同样的问题,我感动了
app.get('*', function (req, res) {
res.sendFile(__dirname + '/public/index.html'); // load the single view file (angular will handle the page changes on the front-end)
});
to server.js right under the require('./app/routes.js')(app);
and that fixed it! Because it was looking for index.html in the wrong place when a server-side route was being called. I think you could have also changed the path too but I found this to be clearer.
在require('。/ app / routes.js')(app)下面的server.js;并修复它!因为它在调用服务器端路由时在错误的位置寻找index.html。我想你也可以改变路径,但我发现这更清楚了。