Node, Angular Error: ENOENT: no such file or directory

I ran the scotch.io tutorial to create my first node and angular application. I saw that relative paths are a common problem on the Internet for Error: ENOENT: no such file or directory, which, as far as I can tell, is the same as in the textbook, so for some reason I do not work.

Full error message: 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 :)

+4
source share
1 answer

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)
  });

server.js require('./app/routes.js')(app); ! index.html . , , .

+3

Source: https://habr.com/ru/post/1653217/


All Articles