Code Explanation Video Link :
https://youtu.be/zwuUdpF4Egk
Code :
const express = require("express");
const app = express();
app.use(sayMyName);
app.get("/", isLoggin, (req, res) => {
console.log("After middleware");
console.log(req.user);
res.send("Welcome to JoBat Virtuschool");
});
function sayMyName(req, res, next) {
console.log("In MiddleWare");
next();
}
function isLoggin(req, res, next) {
if (req.query.isLogin === "true") {
console.log("Login user");
req.user = "Jobat user";
next();
} else {
res.send("Access Denied");
}
}
app.listen(5000, () => {
console.log("Server Running");
});