Reputation: 4526
I am doing a tutorial trying to learn Node and Angular. I am completely new to this, I come from a LAMP stack environment so it's a whole new world to me and I feel completely lost.
I have installed Angular JS and included it in my HTML file but I keep getting this error
http://localhost:3000/node_modules/angular/angular.min.js Failed to load resource: the server responded with a status of 404 (Not Found)
http://localhost:3000/app/app.js Failed to load resource: the server responded with a status of 404 (Not Found)
EDIT: I have tried some different approached but they're all pointing to the /server/
directory.
var appDir = path.dirname(require.main.filename);
var appDir = path.dirname(process.mainModule.filename);
Both of these point to /server/
directory.
My folders structure is as follows:
/server
index.html
This is server.js
var express = require('express');
var mongoose = require('mongoose');
var bodyParser = require('body-parser');
var app = express();
mongoose.connect('mongodb://localhost:27017/social');
app.use('/app', express.static(__dirname + '/app'));
app.use('/node_modules', express.static(__dirname + '/node_modules'));
app.get('/', function(req, res) {
res.sendFile("index.html", {root: '../'});
});
app.listen('3000', function() {
console.log('Listening for localhost 3000');
});
This is app.js
(function() {
angular.module('Social', []);
}());
This is index.html
<!DOCTYPE html>
<html lang="en" ng-app="Social">
<head>
<meta charset="UTF-8">
<title>The title</title>
</head>
<body>
<p>Testing the test</p>
</body>
<script src="node_modules/angular/angular.min.js"></script>
<script src="app/app.js"></script>
</html>
Upvotes: 0
Views: 2753
Reputation: 43708
__dirname
is "The name of the directory that the currently executing script resides in." which is the directory server.js
is in.
So when you are doing:
express.static(__dirname + '/app')
I think it is actually looking for /server/app
which is not correct.
Upvotes: 0