-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
60 lines (42 loc) · 1.74 KB
/
server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
const http = require('http');
const express = require('express');
const bodyParsar = require('body-parser');
const app =express();
// here we are just importing the routes form the admin js
const adminRouter = require('./routes/admin')
app.use('/admin',adminRouter);
const shopRouter = require('./routes/shop')
app.use(shopRouter);
// what is the name of the channel in the same rate of the time period
// in express js middlware work on the top to bottom , if we commented the next method from 1st
//middleware express not call to tje second
// app.use('/',(req,res,next) =>{
// console.log("This is always runs !");
// next();
// })
console.log("This is the type of the everer")
app.use(bodyParsar.urlencoded({extended : false}));
// app.use('/add-product',(req,res,next) => {
// console.log("Neeraj in first middleware")
// res.send(`
// <form action = "/product" method = "POST">
// <label for="fname">Enter product name:</label>
// <input type="text" id="fname" name="fname"><br>
// <button type="submit"value="Submit"> Submit Product </button>
// </form>`);
// // next(); // allow the middlware to request to the next middlware
// });
// app.use('/product',(req,res,next) => {
// res.redirect('/');
// });
// here each USE function is consider as the middlware and next method call the next middlware method
// app.use('/',(req,res,next) =>{
// console.log("This is second middlware in the file time");
// res.send("<h1>This is the first express js app </h1>")
// })
// page is not found error page responce
app.use((req,res,next) =>{
res.status(404).send('<h1>This is the error page </h1>')
})
const server = http.createServer(app);
app.listen(3000);