-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
48 lines (37 loc) · 1.26 KB
/
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
39
40
41
42
43
44
45
46
47
require('dotenv').config()
const express = require('express');
const app = express();
// const db = require('./config/mongoose');
const expressLayouts = require('express-ejs-layouts');
const session = require('express-session');
const flash = require('connect-flash');
const customeMW = require('.//config/middleware');
//middleware to use assets
app.use(express.static('./assets'));
app.use(express.urlencoded());
app.use(expressLayouts);
//extract styles and scripts from layouts
app.set('layout extractStyles', true);
app.set('layout extractScripts', true);
//setting view engine as ejs
app.set('view engine', 'ejs');
app.set('views', './views');
// ************************ Database Connection **********************************//
const {connectMonggose} = require('./config/mongoose')
connectMonggose();
//to create an duse sessions
app.use(session({
secret: process.env.SECRET,
saveUninitialized: true,
resave: true
}));
//using connect-flash to display flash notification in FE
app.use(flash());
app.use(customeMW.setFlash);
//router
app.use('/', require('./routes'));
// ************************ Port Start ********************************//
const PORT = process.env.PORT || 8500;
app.listen(PORT,()=>{
console.log(`My server start on this port ${PORT}`)
})