-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
61 lines (45 loc) · 1.47 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
var express = require("express");
var logger = require("morgan");
var mongoose = require("mongoose");
// Require all models
var db = require("./models");
// Set the port of our application for use on Heroku and local
var PORT = process.env.PORT || 3001;
// Initialize Express
var app = express();
// Set up Router
var router = express.Router();
// Routes
// =============================================================
require("./routes/html-routes.js")(router);
require("./routes/scrape-api-routes.js")(router);
require("./routes/comment-api-routes.js")(router);
// Configure middleware
// 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());
// Make public a static folder
app.use(express.static("public"));
// Set Handlebars.
var exphbs = require("express-handlebars");
app.engine("handlebars", exphbs({ defaultLayout: "main" }));
app.set("view engine", "handlebars");
// Get database - deployed or local
var MONGODB_URI = process.env.MONGODB_URI || "mongodb://localhost/newsarticles";
// Connect to the Mongo DB
mongoose.connect(MONGODB_URI , { useNewUrlParser: true }, function(error) {
if (error) {
console.log(error)
} else {
console.log("mongoose successful connection")
};
});
mongoose.set('useCreateIndex', true);
// user router
app.use(router);
// Start the server
app.listen(PORT, function() {
console.log("App running on port " + PORT + "!");
});