-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexpress.js
More file actions
80 lines (64 loc) · 1.9 KB
/
express.js
File metadata and controls
80 lines (64 loc) · 1.9 KB
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
const bodyParser = require('body-parser');
const express=require('express');
const app=express();
// For Static file -> set Middleware
app.use(express.static(__dirname,'static'));
//View setup
app.set('views',path.join(__dirname,'views'));
app.set('view engine','ejs');
// Use json
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended:true}));
// GET API -> It will Manage your Request and Send response
app.get('/',(req,res)=>{
// res.status(404).send('<h1>Hello World </h1>');
res.status(201).sendFile(__dirname+'/index.html');
});
app.get('/about',(req,res)=>{
res.sendFile(__dirname+'/about.html');
});
app.get('/help',(req,res)=>{
res.send('<h1>Help Page</h1>');
});
// Route Parameters
app.get('/student/login/newone/:id/:name',(req,res)=>{
const id=req.params.id;
const name=req.params.name;
res.send(`<h2>${id} and ${name}</h2>`);
// 00012830
// if(id=='00012830'){
// res.send('<h1>Welcome Back Admin</h1>');
// }
// else{
// res.send('<h1>Wrong Password</h1>');
// }
});
// Route -> form
app.get('/form',(req,res)=>{
res.sendFile(__dirname+'/form.html');
});
// Post API for -> Form
app.post('/uform',(req,res)=>{
// res.send('API Called');
const uname=req.body.uname;
const passw=req.body.passw;
res.status(200).send(`User Name is ${uname} And Your Password is ${passw}`);
});
// 404 page return
app.all('*',(req,res)=>{
res.send('<h1 style="color:red;">404 page not found !!!</h1>')
});
// PORT Define
app.listen(8007,()=>{
console.log('server Start on PORT : 8007');
});
// Response Codes :
// 100-199 -> Information
// 200-299 -> Sucess
// 300-399 -> Redirection
// 400-499 -> Client side Error
// 500-599 -> Server Side Error
// Task 7/7/2023 :
// build Get API For 5 pages + with response code
// Make 404 Page
// Get USer Name & Password Via Route Parameter -> Compare it and send response regarding it