程序找不到我的脚本文件

时间:2015-01-11 18:34:03

标签: javascript angularjs node.js express

我使用带有express和Angularjs的node.js来构建我的网站web, 但是我在控制台中获得了以下输出 好像程序无法找到我的脚本文件

GET http://localhost:3000/images/entet_gauche.gif 404 (Not Found)
GET http://localhost:3000/js/app.js 
Uncaught Error: [$injector:modulerr] http://errors.angularjs.org/1.3.8/$injector/modulerr?p0=MetaStore&p1=Error%…ogleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.3.8%2Fangular.min.js%3A17%3A350)

似乎程序无法找到我的脚本文件 这条路有什么问题?

的index.html

<body ng-app="MetaStore">
  <a class="navbar-brand" href="#">
    <img alt="Brand" src="./images/entet_gauche.gif">
  </a>

  <div ng-controller="produContr" class="container">
    <div class="container-fluid">
      <div class="row">

        <div ng-repeat="product in products | filter:search:strict" class="col-sm-3">
          <h3> {{product.name}} </h3>
          <p> {{product.content}} </p>
          <p><strong>Prix : </strong> {{product.prix}} DH</p>
        </div>

      </div>

    </div>
  </div>

  <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.8/angular.min.js"></script>
  <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/js/bootstrap.min.js"></script>

  <script src="/js/app.js"></script>

</body>

JS / app.js

var app = angular.module(&#39; MetaStore&#39;,[]); app.controller(&#39; produContr&#39;,函数($ scope,$ http,$ interval){

})

server.js

var express = require("express");
var mysql = require("mysql");
var app = express();

var connection = mysql.createConnection({
  host: "localhost",
  user: "root",
  password: "",
  database: "angularjsDB"
});

connection.connect(function(error) {
  if (error) {
    console.log("Problem with MySQL" + error);
  } else {
    console.log("Connected with Database");
  }
});

app.get('/', function(req, res) {
  res.sendFile(__dirname + '/index.html');
});

app.get('/load', function(req, res) {
  connection.query("SELECT * from product", function(err, rows) {
    if (err) {
      console.log("Problem with MySQL" + err);
    } else {
      res.end(JSON.stringify(rows));
    }
  });
});

app.listen(3000, function() {
  console.log("It's Started on PORT 3000");
});

更新: 这是我的目录结构:

index  location -> (folder/index.html) ...
server location -> (folder/server.js) ...
app location -> (folder/js/app.js) ...
picture location ->(folder/images/entet_gauche.gif)

感谢您的关注和了解

1 个答案:

答案 0 :(得分:4)

看起来你没有设置静态文件中间件。在进行路线之前,请添加:

app.use(express.static(__dirname + '/public'));

其中'public'是包含CSS和js文件的文件夹。查看明确的文档,了解您可能需要的其他选项。