forked from hbatatia/f28wp-week7-nodejs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp13-http_routes.js
More file actions
24 lines (23 loc) · 822 Bytes
/
app13-http_routes.js
File metadata and controls
24 lines (23 loc) · 822 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
//load hhtp module
const http = require('http');
//create a HTTP server and register the connect handler
const server = http.createServer((request, response) => {
//check if the route is /
if (request.url === '/') {
response.write("Hello from node.js");
response.end();
}
if (request.url === '/api/players') {
//go to database and get players
//here we mimic this by calling the function getPlayers
//which returns an array of Player objects
//load hhtp module
const getPlayers = require('./app13-players.js');
let players = getPlayers();
response.write(JSON.stringify(players));
response.end();
}
});
//tell the server to listen on port 8000
server.listen(8000);
console.log("Server started and listening on port 8000");