-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.js
35 lines (27 loc) · 947 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
// REQUIRED PACKAGES IN ORDER TO RUN - MORGAN TO SHOW SPECS OF APPLICATION
const express = require("express");
const mongoose = require("mongoose");
const logger = require("morgan");
// WEBSITE DEPLOYED ON GIVEN PORT OR 8080
const PORT = process.env.PORT || 8080;
// EXPRESS METHOD = APP
const app = express();
// ENCODED JSON - NEEDED
app.use(logger("dev"));
app.use(express.urlencoded({ extended: true }));
app.use(express.json());
// LETTING APPLICATION KNOW THERE IS A PUBLIC FOLDER
app.use(express.static("public"));
// CONNECTING TO MONGO DATABASE
mongoose.connect(process.env.MONGODB_URI || "mongodb://localhost/workout", {
useNewUrlParser: true,
useFindAndModify: false,
useUnifiedTopology: true
});
// REQUIRING ROUTES FOR PAGES TO WORK
require("./routes/htmlRoutes.js")(app);
require("./routes/apiRoutes.js")(app);
// APPLICATION IS STARTING
app.listen(PORT, () => {
console.log(`APP RUNNING ON PORT: ${PORT}!`);
});