-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
46 lines (35 loc) · 1.36 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
// require the node modules
var express = require("express");
var bodyParser = require("body-parser");
var exphbs = require("express-handlebars");
var mongoose = require("mongoose");
// create the express app
var app = express();
// set the port of our application
// process.env.PORT lets the port be set by Heroku
var PORT = process.env.PORT || 8080;
// Requiring our models for syncing
var db = require("./models");
// sets up the express app to handle data parsing
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
// serve static content for the app from the "public" directory
app.use(express.static("public"));
// import routes
require("./routes/html-routes.js")(app);
require("./routes/api-routes.js")(app);
// sets up handlebars
app.engine("handlebars", exphbs({ defaultLayout: "main" }));
app.set("view engine", "handlebars");
// If deployed, use the deployed database. Otherwise use the local mongoHeadlines database
var MONGODB_URI = process.env.MONGODB_URI || "mongodb://localhost/fakenews";
// Set mongoose to leverage built in JavaScript ES6 Promises
// Connect to the Mongo DB
mongoose.Promise = Promise;
mongoose.connect(MONGODB_URI);
// connect to Mongo DB
// mongoose.connect("mongodb://localhost/fakenews");
// opens the local server
app.listen(PORT, function() {
console.log(`Server listening on: http://localhost: ${PORT}`);
});