-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
39 lines (36 loc) · 1.26 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
const http = require('http');
const fs = require('fs');
const server = http.createServer(function (request, response){
console.log('client request URL: ', request.url);
// this is how we do routing:
if(request.url === '/') {
fs.readFile('index.html', 'utf8', function (errors, contents) {
response.writeHead(200, {'Content-Type': 'text/html'}); // send data about response
response.write(contents); // send response body
response.end(); // finished!
});
}
else if (request.url === '/ninjas') {
fs.readFile('ninjas.html', 'utf-8', function (errors,contents){
response.writeHead(200,{'Content-Type': 'text/html'});
response.write(contents);
response.end();
});
}
else if (request.url === '/dojos') {
fs.readFile('dojos.html','utf-8', function (errors, contents){
response.writeHead(200,{'Content-Type': 'text/html'});
response.write(contents);
response.end();
});
}
// request didn't match anything:
else {
response.writeHead(404);
response.end('File not found!!!');
}
});
// tell your server which port to run on
server.listen(6789);
// print to terminal window
console.log("Running in localhost at port 6789");