-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Middleware in express.js and adding view in Day 2 folder
- Loading branch information
1 parent
cf13552
commit 23a7a60
Showing
5 changed files
with
2,590 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
Oops, something went wrong.