admin管理员组文章数量:1323529
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 mon 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.
The full error message is:
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:
// 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:
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 have been following the a scotch.io tutorial to create my first node and angular app. I have seen that relative paths are a mon 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.
The full error message is:
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:
// 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:
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 :)
Share Improve this question asked Aug 31, 2016 at 20:52 jSutcliffe90jSutcliffe90 3232 gold badges6 silver badges19 bronze badges 3-
1
Your
public
folder isn't inside theapp
folder in the picture you've posted, so clearlyapp/public/...
is wrong ? – adeneo Commented Aug 31, 2016 at 20:57 - Yeah that's clearly the issue, showing my inexperience here! Which part of the route is adding the "app" part? It's the same as scotch.io but obviously my request is going to a different directory. Isn't app.get just calling express to make the route, rather than adding it to the path? – jSutcliffe90 Commented Aug 31, 2016 at 21:26
- Did you setup app.use(express.static(__dirname + '/public')); so express can serve your static files from the public folder.You can also try out instead import path = require('path'); and then use app.use('/', express.static(path.resolve('./public'))); – ramon22 Commented Aug 31, 2016 at 23:47
1 Answer
Reset to default 4I 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.
本文标签: javascriptNodeAngular Error ENOENT no such file or directoryStack Overflow
版权声明:本文标题:javascript - Node, Angular Error: ENOENT: no such file or directory - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742128431a2422049.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论