-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbelajar-req-res.js
32 lines (28 loc) · 1.02 KB
/
belajar-req-res.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
const http = require('http')
const fs = require('fs')
const port = 3000
let server = http.createServer( function(request, respon) {
if (request.url == '/') {
respon.writeHead(200, {'Content-Type': 'text/html'})
fs.createReadStream('./view/utama.html').pipe(respon)
// fs.createReadStream() => membaca file yg diinginkan
// pipe() => kirim sebagai apa, file yg sudah dibaca
}
else if (request.url == '/beranda') {
respon.writeHead(200, {'Content-Type': 'text/html'})
fs.createReadStream('./view/beranda.html').pipe(respon)
}
else if (request.url == '/profil') {
respon.writeHead(200, {'Content-Type': 'text/html'})
respon.write('<h1>Profil Coach</h1>')
respon.end()
}
else {
respon.writeHead(404, {'Content-Type': 'text/html'})
respon.write('<h1>Putar balik om!, File yang dicari nggak ada!!</h1>')
respon.end()
}
})
server.listen(port, ()=>{
console.log(`server sudah on, buka http://localhost:${port}`)
})