forked from mohitrakhade20/realtime-voting-nodejs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
41 lines (29 loc) · 847 Bytes
/
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
39
40
41
const express = require("express");
const app = express();
const path = require("path");
const http = require("http").createServer(app);
let io = require("socket.io")(http);
const bodyParser = require("body-parser");
const cors = require("cors");
// DB Config
require("./config/db");
// routes
const poll = require("./routes/poll");
// view engine
app.set("view engine",'ejs')
// Set public folder
app.use(express.static(path.join(__dirname, "public")));
// Body parser middleware
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
// Enable CORS
app.use(cors());
// exporting io
app.use('/',(req,res,next)=>{
req.io=io
next()
})
app.use("/", poll);
const port = 8080;
// Start server
http.listen(port, () => console.log(`Server started on port ${port}`));