javascript - Node , Angular 错误 : ENOENT: no such file or directory

标签 javascript angularjs node.js

我一直在关注 a scotch.io创建我的第一个 Node 和 Angular 应用程序的教程。我已经看到相对路径是 Error: ENOENT: no such file or directory 的常见在线问题,据我所知这与教程相同,所以我就是为什么它不起作用.

完整的错误信息是: 错误:ENOENT:没有这样的文件或目录,stat'/Users/badman/githubRepos/travelGuide/app/public/index.html' 错误时( native )

My folder structure is here. 我的 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");
})

路由.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 。我认为您也可以更改路径,但我发现这样更清晰。

关于javascript - Node , Angular 错误 : ENOENT: no such file or directory,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39258797/

相关文章:

javascript - Foundation zurb 导航栏

javascript - 基于 bool 值的 Angular 开关外层 Div

node.js - 如何在 sails.js 中获取当前域地址

javascript - 使用 Angular 属性指令对 SVG 元素进行 IE/Edge 渲染

node.js - Docusign Node.JS JWT 示例 - PEM_read_bio :bad end line

node.js - Google 云打印 API - 打印 PDF 时出现白页

javascript - $watch 中的 Angular 表达式触发两次

javascript - Controller 不使用 angularJS 渲染

javascript - 自动生成和 Javascript

javascript - Angularjs 输入名称未定义