-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
38 lines (29 loc) · 1.05 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
import "dotenv/config";
import cron from "node-cron";
import express from "express";
import mountRoutes from "./routes/index.js";
import bodyParser from "body-parser";
import { errorHandler } from "./middlewares/errorhandlers.js";
import { getLatestItemData } from "./Scripts/tickerUpdate.js";
import { openingValuePull } from "./Scripts/tickerUpdateStartofDay.js";
const app = express();
const port = process.env.PORT || 3000;
app.use(bodyParser.urlencoded({ extended: true }));
app.use("/", express.static("public"));
app.use("/item", express.static("public"));
mountRoutes(app);
// update day values on first startup
openingValuePull();
// cron schedule to automatically update item values every 5 min
cron.schedule("1-56/5 * * * *", () => getLatestItemData(), {
scheduled: true,
});
// cron scheudle to automatically update opening values daily at 00:06 UTC
cron.schedule("6 0 * * *", () => openingValuePull(), {
scheduled: true,
timezone: "Etc/UTC",
});
app.listen(port, () => {
console.log(`Server running on port: ${port}`);
});
app.use(errorHandler);