-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
46 lines (40 loc) · 1.23 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
// 3rd-party packages
const express = require('express'),
ejsLayouts = require('express-ejs-layouts'),
bodyParser = require('body-parser'),
methodOverride = require('method-override'),
session = require('express-session'),
flash = require('express-flash'), // allows flash messaging
auth = require('./lib/auth'),
routes = require('./config/routes'),
mongoose = require('mongoose');
// create the app
const app = express();
const { port, dbURI } = require('./config/environment');
// connect to the database
mongoose.connect(dbURI);
// app settings
app.set('view engine', 'ejs');
app.set('views', `${__dirname}/views`);
// use 3rd-party packages
app.use(ejsLayouts);
app.use(express.static(`${__dirname}/public`));
app.use(bodyParser.urlencoded({ extended: true }));
app.use(methodOverride(req => {
if(req.body && typeof req.body === 'object' && '_method' in req.body) {
const method = req.body._method;
delete req.body._method;
return method;
}
}));
app.use(session({
secret: 'shhh',
resave: false,
saveUninitialized: false
}));
app.use(flash());
app.use(auth);
// routes
app.use(routes);
// listen for incoming traffic -- app.listen()
app.listen(port, () => console.log(`Express is running on port ${port}`));