-
Notifications
You must be signed in to change notification settings - Fork 0
/
basic-routing.js
executable file
·39 lines (26 loc) · 1003 Bytes
/
basic-routing.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
var fs = require('fs')
var http = require('http')
var server = http.createServer(function(req,res) {
console.log('request url' + req.url)
if(req.url === '/home' || req.url === '/' ) {
res.writeHead(200,{ 'Content-Type': 'text/html'})
fs.createReadStream('index.html').pipe(res)
} else if(req.url === '/contact') {
res.writeHead(200,{ 'Content-Type': 'text/html'})
fs.createReadStream('contact.html').pipe(res)
} else if(req.url === '/href') {
res.writeHead(200,{ 'Content-Type': 'text/html'})
fs.createReadStream('href-css.html').pipe(res)
} else if(req.url === '/api/ninjas') {
var message = {
name : 'shiva',
age : '29'
};
res.writeHead(200,{ 'Content-Type': 'application/json'})
res.end(JSON.stringify(message))
} else {
res.writeHead(404)
fs.createReadStream('404.html').pipe(res)
}
});
server.listen(8080,'127.0.0.1')