Angular错误:ENOENT:没有这样的文件或目录

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

本文关键字:文件 错误 ENOENT Angular      更新时间:2023-09-26

我一直在跟踪苏格兰威士忌。io教程来创建我的第一个节点和angular应用程序。我已经看到相对路径是Error: ENOENT: no such file or directory在线的一个常见问题,据我所知,这与教程相同,所以我就是为什么它不起作用。

完整的错误信息是:Error: ENOENT: no such file or directory, stat'/Users/badman/githubRepos/travelGuide/app/public/index.html' at Error (native)

我的文件夹结构在这里。我的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)
  });
};

任何帮助都是感激的:)

我有同样的问题,我移动了

  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。我认为你也可以改变路径,但我发现这样更清楚。