-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
35 lines (29 loc) · 903 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
//Dependancies
const express = require("express");
const mongoose = require("mongoose");
const exphbs = require("express-handlebars");
//Express setup
const PORT = process.env.PORT || 3000;
const app = express();
//Middleware
app.use(express.urlencoded({ extended: true }));
app.use(express.json());
app.use(express.static("public"));
//Handlebars
app.engine("handlebars", exphbs({ defaultLayout: "main" }));
app.set("view engine", "handlebars");
require("./routes/routes")(app);
require("./routes/htmlroutes")(app);
//Connect to Mongo DB
const MONGODB_URI =
process.env.MONGODB_URI || "mongodb://localhost/mongoHeadlines";
mongoose.connect(MONGODB_URI, {
useNewUrlParser: true,
useFindAndModify: false,
useCreateIndex: true,
useUnifiedTopology: true,
});
// Start the server
app.listen(PORT, function () {
console.log("Server listening on: http://localhost:" + PORT);
});