-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
71 lines (52 loc) · 1.86 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
62
63
64
65
66
67
68
69
70
71
const express = require("express");
const exphbs = require("express-handlebars");
const mongoose = require("mongoose");
const bodyParser = require("body-parser");
const request = require("request");
const cheerio = require("cheerio");
//const logger = require("logger");
const app = express();
app.use(express.static("public"));
// set express data parsing
// app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
// set handlebars views
//app.engine("handlebars", exphbs({extname: "handlebars", defaultLayout: "main", layoutsDir: __dirname + "/views/layouts" }));
app.engine("handlebars", exphbs({ defaultLayout: "main" }));
app.set("view engine", "handlebars");
app.set('views', __dirname + '/views')
// models required
require("./models/notes.js");
require("./models/articles.js");
// setup mongoose connection
const databaseUri = "mongodb://localhost/mongoscraper";
const collections = ["scrapedarticles"];
console.log('MONGODB_URI', process.env.MONGODB_URI)
if (process.env.MONGODB_URI) {
console.log('remote')
mongoose.connect(process.env.MONGODB_URI);
} else {
console.log('remote')
mongoose.connect(databaseUri);
}
console.log("created new database: ", databaseUri)
//Get the default connection
var db = mongoose.connection;
/// bind connection to error event
db.on('error', function (err) {
console.log('MongoDB connection error:', err);
});
// log success once in mongoose
db.once("open", function() {
console.log("Mongoose connection successful.");
});
// routes
const routes = require("./controllers/controllers.js");
app.use("/", routes);
console.log("created new database: ", databaseUri)
var port = process.env.PORT || 3000;
app.listen(port, function() {
console.log("App running on port 3000!");
});
// MONGOURI: mongodb://heroku_1qqf4x9g:pcs8m689ekgi02qrtlcr1toe71@ds155577.mlab.com:55577/heroku_1qqf4x9g