-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
39 lines (29 loc) · 932 Bytes
/
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 express = require("express");
const bodyParser = require("body-parser");
const exphbs = require("express-handlebars");
const db = require("./models");
const app = express();
const PORT = process.env.PORT || 8080;
// Establishing our Middleware
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
app.use(express.static("public"));
// Establishing Handlebars as the Template Engine
app.engine("handlebars", exphbs({ defaultLayout: "main" }));
app.set("view engine", "handlebars");
// Establishing our Routes
require("./routes/apiRoutes")(app);
require("./routes/htmlRoutes")(app);
let syncOptions = { force: false };
if (process.env.NODE_ENV === "test") {
syncOptions.force = true;
}
db.sequelize
.sync(syncOptions)
.then(() =>
app.listen(PORT, () =>
console.log(`Server listening on: http://localhost:${PORT}`)
)
);
module.exports = app;