-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
33 lines (26 loc) · 1.02 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
const express = require("express");
const morgan = require('morgan');
const mongoose = require("mongoose");
const {getPollController, postPollController, getAllPollsController, getPollDetailsController, postPublicVoteController} = require('./controller/pollController');
const app = express();
app.set('view engine', 'ejs');
app.use(morgan('dev'));
app.use(express.json());
app.use(express.urlencoded({extended: true}));
//routes
app.get('/create', getPollController);
app.post('/create', postPollController);
app.get('/myPolls', getAllPollsController);
app.get('/pollResult/:id', getPollDetailsController)
app.post('/vote/:id', postPublicVoteController);
app.get('/', (req, res) => {
res.render('home');
});
const PORT = 4000;
mongoose.connect('mongodb://localhost/pole_cc', {useNewUrlParser: true, useUnifiedTopology: true, family: 4})
.then(() => {
app.listen(PORT, () => {
console.log(`Server is running in port ${PORT}`);
});
})
.catch((err) => console.log('Failed to connect database', err))