-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
32 lines (26 loc) · 742 Bytes
/
Copy pathindex.js
File metadata and controls
32 lines (26 loc) · 742 Bytes
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
const getQuote = require("./getQuote");
const fs = require("fs/promises");
const express = require("express");
const app = express();
const port = 3000;
//Api routes
app.get("/api/quote", async(req, res) => {
try {
const randomQuote = await getQuote();
console.log(randomQuote);
res.json({
quote: randomQuote,
});
}
catch (error) {
console.error("Error fetching quote", error);
}
});
//Normal routes
app.get("/",(req, res) => {
res.sendFile(__dirname + "/public/index.html");
});
app.use(express.static(__dirname + "/public"));
app.listen(port, () => {
console.log(`Server is running on port http://localhost:${port}`);
});