-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
41 lines (34 loc) · 1013 Bytes
/
server.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
const express = require("express");
const path = require("path");
const app = express();
const parser = require("./parser.js");
app.use(express.static(path.resolve("public")));
app.set("view engine", "ejs");
app.set("views", path.resolve("views"));
let priceResult = {
binance_sell: null,
binance_buy: null,
bitkub_sell: null,
bitkub_buy: null,
}
async function updateBinace() {
const result = await parser.getDataBinance();
priceResult.binance_buy = result[0];
priceResult.binance_sell = result[1];
};
const randNum = (min, max) => Math.floor(Math.random() * (max - min + 1)) + min;
const minute = (num) => num * 60000;
(function loopRandInterval() {
let duration = randNum(minute(5), minute(10));
setTimeout(() => {
updateBinace();
loopRandInterval();
}, duration);
})();
app.get("/", (req, res) => {
res.render("index", priceResult);
});
app.listen(process.env.port || 3000, () => {
console.log("Server started on port 3000");
console.log("http://localhost:3000/");
});