-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
61 lines (46 loc) · 1.38 KB
/
main.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
54
55
56
57
58
59
60
61
const express = require('express');
const path = require('path');
const bodyParser = require('body-parser');
const mongoose = require('mongoose');
const flash = require('connect-flash');
const config = require('./config/database');
const passport = require('passport');
const session = require('express-session');
//Initialises app
const app = express();
//Establishing mongoose connection
mongoose.connect(config.database);
let db = mongoose.connection;
//Check mongoose connection
db.once('open',function(){
console.log('Connected to mongodb')
});
//Check mongoose errors
db.on('error',function(err){
console.log('err')
});
//Bring models
let User = require('./models/user');
//Load template(pug)
app.set('view engine','pug');
app.set('views',path.join(__dirname, 'views'));
//Body parser middleware
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended : false}))
//Set public folder
app.use(express.static(path.join(__dirname, 'public')));
app.use(flash());
app.use(session({ resave: true,
saveUninitialized: true,
secret: 'secret' }));
//passport config
require('./config/passport')(passport);
//passport middleware
app.use(passport.initialize());
app.use(passport.session());
//app.use(app.router);
//Setting routes
let users = require('./routes/users');
app.use('/',users);
//Starts application in required port
app.listen(8080);