From 4cccf35183198d8d84d6004814b3ad46039a1694 Mon Sep 17 00:00:00 2001 From: Dave Date: Fri, 3 Sep 2021 13:32:23 +1200 Subject: [PATCH] Commented Basic/app.js --- _express/_basic/app.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/_express/_basic/app.js b/_express/_basic/app.js index 814d12e..8777a26 100644 --- a/_express/_basic/app.js +++ b/_express/_basic/app.js @@ -1,3 +1,4 @@ +//Global constant variables const express = require("express"); const log = require("morgan"); const http = require("http"); @@ -6,19 +7,24 @@ const app = express(); app.use(log("short")); +//Basic Middleware example using es6 function to detect an error message +//If it is an even minute it will give you next function "Hello, World!" app.use((req, res, next)=> { const minute = new Date().getMinutes(); if (minute % 2 === 0) { next(); +//Else (if it is an odd number) it will display "Not authorized." } else { res.statusCode = 403; res.end("Not authorized."); } }); +//This is the next middleware that will provide a postive repsonse message app.use((req, res) => { res.writeHead(200, { "Content-Type": "text/plain" }); res.end("Hello, World!"); }); +//creates a server on port 3000 http.createServer(app).listen(3000);