user3628240 user3628240 - 3 months ago 16
Javascript Question

localhost:8080 not working for node server

I recently tried to run node server.js, but for some reason the page is no longer loading, and the browser is just waiting indefinitely. This is the case for both safari and chrome. The code worked fine before and the page would load immediately, but for some reason it stopped working now (not sure if computer updated, or need to install a new version)

If anyone could help figure out why the server will not load it would be greatly appreciated.

my server.js file looks like:

var express = require('express');
var fundsapp = require('./fundsapp.js');
var app = express();

app.use('/js', express.static(__dirname + '/public/js'));
app.use('/libs', express.static(__dirname + '/public/libs'));
app.use('/css', express.static(__dirname + '/public/css'));
app.use('/views', express.static(__dirname + '/public/views'));

// app.use('/public/partials', express.static(__dirname + '/public/partials'));
// app.use('/public/js/controllers', express.static(__dirname + '/public/js/controllers'));
// app.use('/public/services', express.static(__dirname + '/public/js/services'))

app.get('/:cik/:startdate/:enddate/:startingtotal', function (req,res) {
// console.log(fundsapp.absolutedollarvalue(req.params.cik, req.params.startdate, req.params.enddate, req.params.startingtotal))
})

app.get('/api/returns', function(req,res) {
console.log(req.query)
fundsapp.calculateReturns(req.query.startDate, req.query.endDate, res, req.query.cik, req.query.benchmark)
})

app.get('/api/adv', function(req,res) {
console.log(req.query)
fundsapp.absolutedollarvalue(req.query.startDate, req.query.endDate, req.query.cik, req.query.startingAmount, res)
})

//app.get('*', function(req, res) {
// res.sendfile('./public/index.html');
app.get('/', function(req, res) {
res.sendFile('public/index.html' , { root : __dirname});
});

app.listen(8080, function() {
console.log("Listening on port 8080")
})


my index.html file is below:

<!-- public/index.html -->
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<base href="/">

<title>Home</title>

<!-- CSS -->
<!-- <link rel="stylesheet" href="libs/bootstrap/dist/css/bootstrap.min.css"> -->
<link href="//netdna.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.css" rel="stylesheet">
<link rel="stylesheet" href="libs/angular-bootstrap/ui-bootstrap-csp.css">
<link rel="stylesheet" href="css/style.css"> <!-- custom styles -->
<link rel="stylesheet" href="libs/angular-chart.js/dist/angular-chart.css">
<link rel="stylesheet" href="libs/angular-ui-grid/ui-grid.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/angular-material/1.0.4/angular-material.css">

<!-- JS -->
<script src="libs/angular/angular.min.js"></script>
<script src="libs/angular-route/angular-route.min.js"></script>
<script src="libs/Chart.js/Chart.js"></script>
<script src="libs/angular-chart.js/dist/angular-chart.min.js"></script>
<script src="//angular-ui.github.io/bootstrap/ui-bootstrap-tpls-1.3.3.js"></script>
<script src="libs/angular-ui-grid/ui-grid.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.4/angular-animate.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.4/angular-aria.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular-material/1.0.4/angular-material.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.5.3/angular-messages.min.js"></script>


<!-- ANGULAR CUSTOM -->
<script src="js/controllers/MainCtrl.js"></script>
<script src="js/controllers/TestCtrl.js"></script>
<script src="js/controllers/AdvCtrl.js"></script>
<script src="js/controllers/ReturnsCtrl.js"></script>
<script src="js/appRoutes.js"></script>
<script src="js/app.js"></script>
<script src="js/config.js"></script>
</head>
<body ng-app="alphaApp" ng-controller="TestController">
<div class="container">

<!-- HEADER -->
<nav class="navbar navbar-inverse">
<div class="navbar-header">
<a class="navbar-brand" href="/">Home</a>
</div>

<!-- LINK TO OUR PAGES. ANGULAR HANDLES THE ROUTING HERE -->
<ul class="nav navbar-nav">
<li><a href="/returns">Returns</a></li>
<li><a href="/adv">Absolute Returns</a></li>
</ul>
</nav>

<!-- ANGULAR DYNAMIC CONTENT -->
<div ng-view></div>

</div>
</body>
</html>


If any additional information would be helpful please let me know. I'm confused why all of a sudden it stopped loading. I tried uninstalling and reinstalling node, npm, express, and bower to no avail.

Thanks for any help!

EDIT:
It looks like from the index.html file it is trying to access the libs folder which I no longer see in the folder. Is there an easy way to install a libs folder filled with the angular files?

Answer

Looks like you are referencing the libs folder here:

<script src="libs/angular/angular.min.js"></script>
<script src="libs/angular-route/angular-route.min.js"></script>
<script src="libs/Chart.js/Chart.js"></script>

Why don't you change these lines to wherever your vendor js files are?

Comments