[英]Node, Angular Error: ENOENT: no such file or directory
I have been following the a scotch.io tutorial to create my first node and angular app. 我一直在关注scotch.io教程来创建我的第一个节点和角度应用程序。 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. 我已经看到相对路径是Error: ENOENT: no such file or directory
在线常见问题Error: ENOENT: no such file or directory
,据我所知,它与教程相同,所以我就是为什么它不起作用。
The full error message is: Error: ENOENT: no such file or directory, stat'/Users/badman/githubRepos/travelGuide/app/public/index.html' at Error (native)
完整的错误消息是: Error: ENOENT: no such file or directory, stat'/Users/badman/githubRepos/travelGuide/app/public/index.html' at Error (native)
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 :) 任何帮助表示赞赏:)
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);
到require('./app/routes.js')(app);
下的server.js 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. 因为它在调用服务器端路由时在错误的位置寻找index.html 。 I think you could have also changed the path too but I found this to be clearer. 我想你也可以改变路径,但我发现这更清楚了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.