-
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.22 KB
/
server.js
File metadata and controls
48 lines (43 loc) · 1.22 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 { json } = require('express')
const express = require('express')
const app = express()
const PORT = 8000
const rappers = {
'aesop': {
'age': 46,
'birthName': "Ian Matthias Bavitz",
'birthLocation': "Long Island, New York",
},
'deltron': {
'age': 49,
'birthName': "Teren Delvon Jones",
'birthLocation': "Oakland, California",
},
'killer mike': {
'age': 29,
'birthName': "Michael Santiago Render",
'birthLocation': "Atlanta, Georgia",
},
'unknown': {
'age': 0,
'birthName': "unknown",
'birthLocation': "unknown",
},
}
app.get('/', (req, res) => {
res.sendFile(__dirname + '/index.html')
})
app.get('/api/:name', (req, res) => {
console.log(req.params.name + ' was requested');
let rapperName = req.params.name.toLowerCase()
if (rappers[rapperName]) {
console.log(req.params.name + ' exists in the database');
res.json(rappers[rapperName])
} else {
console.log(req.params.name + ' does not exists in the database');
res.json(rappers['unknown'])
}
})
app.listen(PORT, () => {
console.log(`the server is now running in port ${PORT} betta cach them all`);
})