This tutorial goes with Aaroh's makingApi-server. You can also see how to achieve the same thing with jQuery in makingApi-client.
- Because our project will be making requests to a server, we'll need a very basic server to send static HTML/JS files. First create a package.json file:
{
"dependencies": {
"express": "^4.13.3"
}
}
- Now in GitBash in your project directory, run
npm install
. This will install Express onto your computer. - Now that we have our dependencies installed, create a server.js:
// This file creates a simple server for us to use
// Not important to understand
var
express = require('express'),
app = express();
app.use(express.static(__dirname + '/', {}));
app.get('/', function (req, res) {
res.sendFile(__dirname + '/index.html');
});
app.listen(9000);
console.log('Magic happens on port 9000');
- This server is used to serve a basic website by sending HTML/JS files to the browser. These files will let the browser send requests to the API we made. Also notice that we used port 9000, which must be different from the first port we used.
- Now download and drag app.module and app.config (from this Github repo) into the current directory.