forked from Elpugna/Node-Express-Course
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path12- HTTP module.js
More file actions
27 lines (25 loc) · 1.05 KB
/
12- HTTP module.js
File metadata and controls
27 lines (25 loc) · 1.05 KB
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
// HTTP, BUILT-IN MODULE - Interacting with the server
//we won't see all the methods in this module, we'll se them later
const http = require("http");
//request = the info coming from the user to the server
//response = the ingo going to the user from the server
const server = http.createServer((request, response)=>{
if(request.url === '/'){
// response.write("Welcome to our homepage");
// response.end();
//the same as:
response.end("Welcome to our homepage");
//I need to use the return to avoid having the error, because it seems to keep on trying to send the last response.end (the one outside the if statements), and it stops the process.
return;
}
if(request.url === '/about'){
response.end("Here is our short history");
return;
}
//I can use "else" here instead of needing a return statement inside every if block.
response.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)