-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
44 lines (30 loc) · 1.07 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
40
41
42
var express = require("express");
var mongoose = require("mongoose");
var logger = require("morgan");
//initialize express
var app = express();
var PORT = process.env.PORT || 3000;
// var db = require("./models");
var db = require("./models");
// Make public a static folder
app.use(express.static("public"));
//Sets up Express-Handlebars
var exphbs = require("express-handlebars");
app.engine("handlebars",exphbs({defaultLayout:"main"}));
app.set("view engine","handlebars");
// Use morgan logger for logging requests
app.use(logger("dev"));
// Parse request body as JSON
app.use(express.urlencoded({ extended: true }));
app.use(express.json());
// Connect to the Mongo DB
mongoose.set("useFindAndModify", false);
var MONGODB_URI = process.env.MONGODB_URI || "mongodb://localhost/newsdb";
mongoose.connect(MONGODB_URI, { useNewUrlParser: true });
// mongoose.connect("mongodb://localhost/newsdb", { useNewUrlParser: true });
// route
require("./routes/router.js")(app,db);
// Start the server
app.listen(PORT, function() {
console.log("App running on port " + PORT + "!");
});