Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions 01-node-tutorial/notes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This part of the course is already present in Backend repository.
62 changes: 61 additions & 1 deletion 02-express-tutorial/app.js
Original file line number Diff line number Diff line change
@@ -1 +1,61 @@
console.log('Express Tutorial')
const http = require("http");
const { readFileSync } = require("fs");

// get all the files
const homePage = readFileSync("./navbar-app/index.html");
const stylesPage = readFileSync("./navbar-app/styles.css");
const logo = readFileSync("./navbar-app/logo.svg");
const logicFile = readFileSync("./navbar-app/browser-app.js");

// https://nodejs.org/docs/latest/api/http.html#responseenddata-encoding-callback
// docs related to status code : https://developer.mozilla.org/en-US/docs/Web/HTTP/Status
const server = http.createServer((req, res) => {
// home page
if (req.url === "/") {
res.writeHead(200, {
"content-type": "text/html",
});
res.write(homePage);
res.end();
} else if (req.url === "/styles.css") {
res.writeHead(200, {
"content-type": "text/css",
});
res.write(stylesPage);
res.end();
} else if (req.url === "/logo.svg") {
res.writeHead(200, {
"content-type": "image/svg+xml",
});
res.write(logo);
res.end();
} else if (req.url === "/browser-app.js") {
res.writeHead(200, {
"content-type": "text/js",
});
res.write(logicFile);
res.end();
}
// about page
else if (req.url === "/about") {
res
.writeHead(200, {
"content-type": "text/html",
})
.end("<h2>This is About page</h2>");
}
// 404 page
else {
res
.writeHead(404, {
"content-type": "text/html",
})
.end("<h2>Page not found.</h2>");
}
});

// port is just a communication endpoint
// learn more : https://en.wikipedia.org/wiki/Port_(computer_networking)
server.listen(5000, () => {
console.log("Server is listening on port : 5000");
});
13 changes: 13 additions & 0 deletions 02-express-tutorial/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Home Page</title>
</head>
<body>
<h1>This is home page</h1>
<h4>hello world</h4>
<h6>-by divyanshi manral</h6>
</body>
</html>
1 change: 1 addition & 0 deletions 02-express-tutorial/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.