我一直在关注 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/