-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
36 lines (30 loc) · 924 Bytes
/
index.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
const express = require("express");
const app = express();
const bodyParser = require("body-parser");
app.use(express.static('public'));
require("dotenv").config()
let PORT = process.env.PORT || 8080
const cors = require('cors')
const quickmongo = require('quickmongo');
const db = new quickmongo.Database(process.env.DBURL);
db.on("ready", async () => {
console.log("[QuickMongo] Connected to the Database.");
});
app.use(cors())
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
app.get("/articles", async (req, res) => {
let articles = await db.get('articles');
res.send(articles)
})
app.listen(PORT, console.log("[Express] Listening to port " + PORT))
//Render Magic
/**
setInterval(() => {
fetch("https://backend-ddu1.onrender.com/articles")
.then(response => response.json())
.catch(error => {
console.error(error);
});
}, 10000);
**/