-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
61 lines (49 loc) · 1.49 KB
/
server.js
File metadata and controls
61 lines (49 loc) · 1.49 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
const express = require("express");
const app = express();
const bodyParser = require("body-parser");
app.use(bodyParser.json());
const albumsData = [
{
albumId: "10",
artistName: "Beyoncé",
collectionName: "Lemonade",
sartworkUrl100:
"http://is1.mzstatic.com/image/thumb/Music20/v4/23/c1/9e/23c19e53-783f-ae47-7212-03cc9998bd84/source/100x100bb.jpg",
releaseDate: "2016-04-25T07:00:00Z",
primaryGenreName: "Pop",
url:
"https://www.youtube.com/embed/PeonBmeFR8o?rel=0&controls=0&showinfo=0"
},
{
albumId: "11",
artistName: "Beyoncé",
collectionName: "Dangerously In Love",
artworkUrl100:
"http://is1.mzstatic.com/image/thumb/Music/v4/18/93/6d/18936d85-8f6b-7597-87ef-62c4c5211298/source/100x100bb.jpg",
releaseDate: "2003-06-24T07:00:00Z",
primaryGenreName: "Pop",
url:
"https://www.youtube.com/embed/ViwtNLUqkMY?rel=0&controls=0&showinfo=0"
}
];
app.get("/albums", function(req, res) {
res.send(albumsData);
});
app.get("/albums/:albumId", function(req, res) {
res.send(req.params.albumId)
// albumID = 10
const albumId = req.params.albumId;
const album = albumsData.find(function (item) {
return item.albumId === albumId
})
res.send(album);
console.log()
});
app.post("/albums", function(req, res) {
console.log(req.body)
albumsData.push(req.body)
res.send()
});
app.listen(3000, function() {
console.log("Server is listening on port 3000. Ready to accept requests!");
});