forked from cs4241-21a/a4-creative-coding
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
49 lines (40 loc) · 1.23 KB
/
server.js
File metadata and controls
49 lines (40 loc) · 1.23 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
// server.js
// where your node app starts
// we've started you off with Express (https://expressjs.com/)
// but feel free to use whatever libraries or frameworks you'd like through `package.json`.
const express = require("express");
const fs = require("fs");
const bodyparser = require("body-parser");
const favicon = require("serve-favicon");
const path = require("path");
const app = express();
// make all the files in 'public' available
// https://expressjs.com/en/starter/static-files.html
app.use(express.static("public"));
app.use(express.static("data"));
//add favicon
app.use(favicon(path.join(__dirname, "/", "favicon.ico")));
app.use(express.json());
app.use(bodyparser.json());
app.use(express.urlencoded({ extended: true }));
app.listen(3000);
// https://expressjs.com/en/starter/basic-routing.html
app.get("/", (request, response) => {
response.sendFile(__dirname + "/views/index.html");
});
app.get("/index.html", (request, response) => {
response.redirect("/");
});
app.get("/lyrics", bodyparser.json(), (request, response) => {
//read the lyrics directory
fs.readdir("data", (err, files) => {
if (err)
console.log(err);
else {
//return files
//console.log(files);
response.json(files);
}
})
//.then
});