-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
86 lines (72 loc) · 1.5 KB
/
server.js
File metadata and controls
86 lines (72 loc) · 1.5 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
81
82
83
84
85
86
const express = require('express')
const app = express()
app.use(express.json())
let currentUser = {
id:'987',
name: 'Jane',
age: '32',
hairColor: 'black',
hobbies: ['swimming', 'party']
}
let users = [{
id: '123',
name: 'Sara',
age: '29',
hairColor: 'brown',
hobbies: ['sport', 'theater']
},
{
id: '987',
name: 'Jane',
age: '32',
hairColor: 'black',
hobbies: ['swimming', 'party']
},
{
id: '768',
name: 'Jak',
age: '38',
hairColor: 'blond',
hobbies: [, 'books']
}]
const products = [{
id: '1234',
name: 'Tv',
price: '200$',
description: 'LED Screen, a great sale',
rating: 4.5
},
{
id: '3456',
name: 'Runnig shoes',
price: '100$',
description: 'Amazing running experience!',
rating: 4.2
},
{
id: '3234',
name: 'Own',
price: '60$',
description: 'Cooking problems finished! Be your own chef!',
rating: 3.8
}]
app.get('/current-user', (req, res) => {
res.json(currentUser)
})
app.get('/users/:id', (req, res) => {
const { id } = req.params;
res.json(users.find(user => user.id === id))
})
app.get('/users', (req, res) => {
res.json(users)
})
app.get('/products/:id', (req, res) => {
const { id } = req.params
res.json(products.find(product => product.id === id))
})
app.get('/products', (req, res) => {
res.json(products)
})
app.listen(8080, () => {
console.log('Server is listening on port 8080!')
})