-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path12-http.js
36 lines (34 loc) · 1001 Bytes
/
12-http.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
const http = require('http')
const server = http.createServer((req, res) => {
// if (req.url === '/') {
// res.end('Welcome to our home page')
// }
// if (req.url === '/about') {
// res.end('Here is our short history')
// }
// res.end(`
// <h1>Oops!</h1>
// <p>We can't seem to find the page you are looking for</p>
// <a href="/">back home</a>
// `)
// ###################################
// ###################################
//
// IF YOU GET ERRORS WHILE USING ABOVE SETUP,
// SWITCH TO IF, ELSE IF, ELSE (BELOW)
// WE COVER THE CAUSE, LATER IN EXPRESS TUTORIAL
if (req.url === '/') {
res.end('Welcome to our home page')
} else if (req.url === '/about') {
res.end('Here is our short history')
} else {
res.end(`
<h1>Oops!</h1>
<p>We can't seem to find the page you are looking for</p>
<a href="/">back home</a>
`)
}
})
server.listen(5000, () => {
console.log('Server listening on port : 5000....')
})