-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
54 lines (41 loc) · 1.38 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
// Dependencies
var express = require("express");
var bodyParser = require("body-parser");
var logger = require("morgan");
var mongoose = require("mongoose");
var exphbs = require("express-handlebars");
// Set mongoose to leverage built in JavaScript ES6 Promises
mongoose.Promise = Promise;
// Initialize Express
var app = express();
// Use morgan and body parser with our app
app.use(logger("dev"));
app.use(bodyParser.urlencoded({
extended: false
}));
// Make public a static dir
app.use(express.static("public"));
// Set Handlebars.
app.engine("handlebars", exphbs({ defaultLayout: "main" }));
app.set("view engine", "handlebars");
// for development
// Database configuration with mongoose
// mongoose.connect("mongodb://localhost/echojsdb");
// for production:
mongoose.connect("mongodb://heroku_b07lx30s:[email protected]:41242/heroku_b07lx30s");
var db = mongoose.connection;
// Show any mongoose errors
db.on("error", function(error) {
console.log("Mongoose Error: ", error);
});
// Once logged in to the db through mongoose, log a success message
db.once("open", function() {
console.log("Mongoose connection successful.");
});
// Routes
app.use("/api", require("./routes/api"));
app.use("/", require("./routes/view"));
var PORT = process.env.PORT || 8000;
app.listen(PORT, function() {
console.log("App listening for requests on PORT " + PORT);
});