-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
48 lines (43 loc) · 1.08 KB
/
Copy pathserver.js
File metadata and controls
48 lines (43 loc) · 1.08 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
const express = require('express');
const app = express();
const bodyParser = require('body-parser')
app.use(bodyParser.json())
const mockUserData=[
{name: 'Mark'},
{name: 'Jill'}
]
app.get('/users', function(req, res) {
res.json({
success: true,
message: 'successfully got users!',
users: mockUserData
})
})
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', function(req, res) {
const username=req.body.username;
const password=req.body.password;
const mockUsername="krish";
const mockPassword="nan";
if (username == mockUserName && password == mockPassword) {
res.json({
success: true,
message: 'password and username match!',
token: 'encrypted token' })
} else {
res.json({
success: false,
message: 'wrong username or password!',
})
}
})
app.listen(8000, function(){
console.log("server is running")
})