Skip to content

Commit

Permalink
Day 3
Browse files Browse the repository at this point in the history
Middleware in express.js and adding view in Day 2 folder
  • Loading branch information
Rahul-Bhati committed Sep 24, 2022
1 parent cf13552 commit 23a7a60
Show file tree
Hide file tree
Showing 5 changed files with 2,590 additions and 0 deletions.
24 changes: 24 additions & 0 deletions Day 2/view/demo.pug
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
html
head
title Demo
body
h1 Pug File
table
tr
td 1
td rahul
td 78
tr
td 2
td ajay
td 79
tr
td=ename
td=salary
td=mobile

h1 #{ename}
table
tr
td=exp[0]
td=exp[1]
34 changes: 34 additions & 0 deletions Day 3/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Day 4 (Middleware)

const express = require("express");
const app = express();

app.set("view engine", "pug");
app.set("views", "./view");

/*
function display(request, response, next) {
console.log("display");
next();
});
app.use(display);
app.get("/", function (request, response) {
response.render('demo');
});
*/
function employee(request, response, next) {
// sbse phele ye load hota h
var emp = {
// object
ename: "Rahul" , salary: 120000000 , mobile: "904242592",
};
request.emp = emp; // add object with request
next(); // reload ko stop kr deta h eske bina refresh wala chakr ghumta rhe ga
}
app.use(employee); // use nhi krege to middleware load / use nhi hoga
app.get("/", function (request, response) {
response.send(
request.emp.ename + " " + request.emp.salary + " " + request.emp.mobile
);
});
app.listen(5000);
Loading

0 comments on commit 23a7a60

Please sign in to comment.