From d5d94f7caa2ffbf5788957f01b05ed5d9ca5c823 Mon Sep 17 00:00:00 2001 From: Prashansha Date: Wed, 6 Mar 2024 08:50:10 +0530 Subject: [PATCH 1/2] added note --- 01-node-tutorial/notes.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 01-node-tutorial/notes.md diff --git a/01-node-tutorial/notes.md b/01-node-tutorial/notes.md new file mode 100644 index 0000000000..d43402c296 --- /dev/null +++ b/01-node-tutorial/notes.md @@ -0,0 +1 @@ +This part of the course is already present in Backend repository. \ No newline at end of file From 50dec0d67d38d29c0b8a3aa651b8304514845e79 Mon Sep 17 00:00:00 2001 From: Prashansha Date: Mon, 11 Mar 2024 10:47:36 +0530 Subject: [PATCH 2/2] basics before express --- 02-express-tutorial/app.js | 62 ++++++++++++++++++++++++++- 02-express-tutorial/index.html | 13 ++++++ 02-express-tutorial/package-lock.json | 1 + 3 files changed, 75 insertions(+), 1 deletion(-) create mode 100644 02-express-tutorial/index.html diff --git a/02-express-tutorial/app.js b/02-express-tutorial/app.js index ce296a6ee3..754eec6313 100644 --- a/02-express-tutorial/app.js +++ b/02-express-tutorial/app.js @@ -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("

This is About page

"); + } + // 404 page + else { + res + .writeHead(404, { + "content-type": "text/html", + }) + .end("

Page not found.

"); + } +}); + +// 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"); +}); diff --git a/02-express-tutorial/index.html b/02-express-tutorial/index.html new file mode 100644 index 0000000000..3777968748 --- /dev/null +++ b/02-express-tutorial/index.html @@ -0,0 +1,13 @@ + + + + + + Home Page + + +

This is home page

+

hello world

+
-by divyanshi manral
+ + diff --git a/02-express-tutorial/package-lock.json b/02-express-tutorial/package-lock.json index 417394ff8b..8bb5c6b82e 100644 --- a/02-express-tutorial/package-lock.json +++ b/02-express-tutorial/package-lock.json @@ -5,6 +5,7 @@ "requires": true, "packages": { "": { + "name": "2-express-tutorial", "version": "1.0.0", "license": "ISC", "dependencies": {