Pratik Gaikwad Pratik Gaikwad - 1 month ago 16
Node.js Question

The server has not found anything matching the requested URI node

I have below folder structure in VS2015:

Folder structure for Node web app

The server.js has below code:

var express = require('express')
var app = express();
var http = require('http').Server(app);
var path = require('path');

var port = process.env.port || 1337;
app.use(express.static(__dirname + 'client'));
app.get('/', function (req, res) {
res.sendFile(path.join(__dirname,'client', 'HTML1.html'));
});

http.listen(port, function () {
console.log(`listning on ${port}`);
})


and Html1.Html has below code:

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head data-ng-app="imageLoaderApp">
<meta charset="utf-8" />
<title></title>
</head>
<body>
<div>

</div>
<script src="/client/scripts/angular.js"></script>
<script type="text/javascript">
var app = angular.module('imageLoaderApp', []);
app.controller('loadController', function ($scope) {
console.log(`i'm here.'`);
});
</script>
</body>
</html>


When I'm hitting below url in browser

http://localhost:1337/

I'm getting below error in console:

enter image description here

This is happening with all the js files. I even tried to move the html and js files in main folder still getting the same error.

What am I doing wrong?

Answer

It looks like HTML1.html is in the client folder. If that is the case I think you need to put the path to the js relative to it so: 'src="scripts/angular.js"'