-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
39 lines (35 loc) · 1 KB
/
server.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
require('dotenv').config();
const exphbs = require('express-handlebars');
const express = require('express');
const path = require('path');
const sequelize = require('./config/connection');
const router = require('./controllers');
const helpers = require('./util/helpers');
const sessionMiddleware = require('./config/session');
const PORT = process.env.PORT || 3001;
const app = express();
// setup app middleware
app.use(sessionMiddleware);
app.use(express.static(path.join(__dirname, 'public')));
app.engine('handlebars', exphbs({ helpers }));
app.set('view engine', 'handlebars');
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
// connect routes
app.use(router);
// connect db and listen
sequelize
.sync({ force: false })
.then(() => {
app.listen(PORT, (err) => {
if (err) {
console.error(err);
return process.exit(1);
}
console.log(`App listening on PORT ${PORT}`);
});
})
.catch((err) => {
console.error(err);
process.exit(1);
});