-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathapp.js
55 lines (40 loc) · 1.16 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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
const express = require('express');
const morgan = require('morgan');
const mongoose = require('mongoose');
let dotenv = require("dotenv");
let cookieParser = require("cookie-parser")
let flash =require("connect-flash")
let session = require("express-session")
let path = require("path")
dotenv.config();
const app = express();
// connection to Mongo db
mongoose.connect(process.env.MONGODB_HOST,{
useNewUrlParser:true,
useUnifiedTopology:true
})
.then(db => console.log('db connected'))
.catch(err => console.log(err));
// importing routes
const indexRoutes = require('./routes/routeindex');
// settings
app.set('port', process.env.PORT || 3000);
app.set('views',path.join(__dirname, "views"));
app.set('view engine', 'ejs');
// middlewares
app.use(morgan('dev'));
app.use(express.urlencoded({extended:false}));
app.use(cookieParser())
app.use(express.static(path.join(__dirname, 'public')));
app.use(flash());
app.use(session({
secret: 'myscret',
resave: false,
saveUninitialized:false
}))
// routes
app.use('/', indexRoutes);
app.listen(app.get('port'), () =>{
console.log(`server on port ${app.get('port')}`);
})
module.exports = app