I'm working on creating a web application that uses AngularJS's data binding tactics to create a very nice frontend based on the backend data model. However, the backend data needs to come from incoming HTTP post requests, which I've figured out I'm going to use NodeJS to handle.
Right now I'm using an Xampp local web server to do all the testing, and here is the file structure I've setup.
As you can see, I've created a website directory for my website files, and when I visit localhost/website
in my browser, the page loads the files I have. Currently, I have Angular up and running with this source code:
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.7/angular.min.js"></script>
<link rel="stylesheet" href="style.css" />
<script src="script.js"></script>
</head>
<body ng-app>
<h1>{{80/5}}</h1>
</body>
</html>
And the only text on the page is 16, as it is expected.
My question is, how can I also have a NodeJS server running at the same location (localhost/website
) so that when HTTP requests are sent to this web URL, they are intercepted and handled by Node, which can pass the results that are processed directly to Angular to handle the frontend stuff? Can you create the Node server inside of the script.js
file I have? And what host/port would I use to grab the incoming HTTP requests?