-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
53 lines (43 loc) · 1.1 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
const express=require('express')
const app=express()
const bodyParser=require('bodyParser')
app.use(bodyParser.json())
const mockUserData=[
{name:'Mark'},
{name:'Jill'}
]
app.get('/users',function(req,res){
res.json({
success: true,
message: 'successfully got users. Nice!',
users: mockUserData
})
})
// colons are used as variables that be viewed in the params
app.get('/users/:id',function(req,res){
console.log(req.params.id)
res.json({
success: true,
message: 'got one user',
user: req.params.id
})
})
app.post('/login',(req,res)=>{
const username=req.body.username
const password=req.body.password
const mockUsername='billyThekid'
const mockPassword='superSecret'
if(username===mockUsername &&password===mockPassword){
res.json({
success:true,
message:'password and username match!',
token:'ecrypted token here'
})
}else{
res.json({
success:false,
message:'password and username do not match'
})
}
})
app.listen(8000,()=>{console.log('Server is running on Port 8000')})