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 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("