-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
56 lines (43 loc) · 1.06 KB
/
app.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
54
55
56
const sqlite3 = require('sqlite3').verbose();
let express = require("express");
let app = express();
// WebSockets assignment
let WebSocket = require('ws');
let wss = new WebSocket.Server({
port:process.env.PORT || 8080
});
wss.on("connection", function(ws){
ws.on("message", function(message){
wss.clients.forEach((client) => {
client.send(message);
});
});
});
/* PREVIOUS ASSIGNMENT
app.get('/api/artists', function(request, response){
let db = new sqlite3.Database('chinook.db', (err) => {
if (err) {
return console.error(err.message);
}
let sql = `SELECT * FROM artists`;
if (request.query.filter) {
sql += ` WHERE NAME LIKE '%${request.query.filter}%'`;
}
var artistsList = []
db.all(sql,[],(err, rows ) => {
if (err) {
throw err;
}
rows.forEach((row)=>{
artistsList.push(row);
});
response.json(artistsList);
});
});
db.close((err) => {
if (err) {
return console.error(err.message);
}
});
}); */
app.listen(process.env.PORT || 8000);