-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
38 lines (27 loc) · 884 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
37
38
const express = require('express');
const http = require('http');
const dotenv = require('dotenv');
const path = require('path');
const cors = require('cors');
const fetch = require('node-fetch');
const app = express();
const server = http.createServer(app);
dotenv.config();
const { initPG } = require("./db-config");
// makes all static files available
app.use(express.static(path.join(__dirname,'./public')));
// lots of middlewares
app.use(cors());
app.use(express.json());
app.use(express.urlencoded({extended: false}));
// import router
const router = require("./router");
// use router (for all paths)
app.use(router);
// to be called only once when starting server afresh
// ensure DB has correct parsers etc set up
initPG();
// logs whenever https server port 3000 receives connection
server.listen(3000, () => {
console.log('Server listening on port 3000');
});