-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
53 lines (40 loc) · 1.22 KB
/
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
42
43
44
45
46
47
48
49
50
51
52
53
require("dotenv").config();
const express = require("express");
const cors = require("cors");
const morgan = require("morgan");
const { fetchAndSaveTweets } = require("./lib/fetchTweets");
const { connect: connectDB } = require("./lib/db");
const app = express();
const PORT = process.env.PORT || 4000;
app.use(morgan(process.env.NODE_ENV == "production" ? "common" : "dev"));
app.use(express.json());
app.options("/volunteer/*", cors());
app.use(cors());
console.log(
"⚠️Starting ",
process.env.NODE_ENV == "production" ? "prod" : "staging",
" Environment"
);
connectDB()
.then(() => {
console.log("✅ Database Connected!");
fetchAndSaveTweets();
if (
process.env.NODE_ENV === "production" ||
process.env.NODE_ENV == "staging"
) {
setInterval(async () => {
console.log("Fetching Tweets...");
console.time("fetchTweets");
await fetchAndSaveTweets();
console.timeEnd("fetchTweets");
console.log("Done Fetching Tweets!");
}, 3000);
setInterval(async () => {
console.log("Deleting Tweets...");
await fetchAndSaveTweets();
console.log("Done Deleting Tweets!");
}, 3000);
}
})
.catch(console.error);