user3514348
user3514348

Reputation: 59

Program can't find my script files located

I am using node.js with express and Angularjs to build my site web, but i'm getting the following output in the console It seems like the program can't find my script files located

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)

It seems like the program can't find my script files located What is wrong with the path?

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('MetaStore', []); app.controller('produContr', function($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");
});

update : this is my directory structure :

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

Thanks for your attention and for taking a look

Upvotes: 0

Views: 6003

Answers (1)

Paul
Paul

Reputation: 36319

Looks like you've not setup the static file middleware. Before you do routes, add:

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

Where 'public' is the folder with your CSS and js files. Check the express docs for other options you might want.

Upvotes: 4

Related Questions