-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
51 lines (40 loc) · 1.37 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
// Include Server Dependencies
const express = require("express");
const bodyParser = require("body-parser");
const logger = require("morgan");
const mongoose = require("mongoose");
// Set mongoose to leverage built in JavaScript ES6 Promises
mongoose.Promise = Promise;
// Create Instance of Express
const app = express();
// Sets an initial port. We'll use this later in our listener
const PORT = process.env.PORT || 3000;
// Run Morgan for Logging
app.use(logger("dev"));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.text());
app.use(bodyParser.json({ type: "application/vnd.api+json" }));
app.use(express.static("public"));
// -------------------------------------------------
// MongoDB Configuration configuration
mongoose.connect("mongodb://heroku_ht48r83d:[email protected]:29374/heroku_ht48r83d", {
useMongoClient: true
});
// mongoose.connect("mongodb://localhost/TestNYTReact", {
// useMongoClient: true
// });
let db = mongoose.connection;
db.on("error", function(err) {
console.log("Mongoose Error: ", err);
});
db.once("open", function() {
console.log("Mongoose connection successful.");
});
// -----------------------------------------------
// require routes
require('./routes/routes.js')(app);
// Listener
app.listen(PORT, function() {
console.log("App listening on PORT: " + PORT);
});