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.
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 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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With