-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
30 lines (24 loc) · 923 Bytes
/
server.js
File metadata and controls
30 lines (24 loc) · 923 Bytes
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
const express = require("express");
const bodyParser = require("body-parser");
const mongoose = require("mongoose");
const app = express();
const env = require("dotenv").config();
const port = process.env.PORT || 3000;
const MONGODB_URI =
process.env.MONGODB_URI || "mongodb://localhost/nytHeadlines";
app.use(express.static("public"));
app.use(bodyParser.urlencoded({extended: true}));
app.use(bodyParser.json());
const exphbs = require("express-handlebars");
app.engine("handlebars", exphbs({defaultLayout: "main"}));
app.set("view engine", "handlebars");
require("./controllers/news_controller")(app);
mongoose.Promise = Promise;
mongoose.connect(MONGODB_URI, { keepAlive: 120 })
.then(
() => {
console.log("Mongoose connection successful.");
app.listen(port, () => console.log(`Server listening on: http://localhost:${port}`));
},
error => console.log("Mongoose connection unsuccessful.")
);