{"size": 1074, "ext": "js", "max_stars_repo_path": "server.js", "max_stars_repo_name": "jeffreylowy/mongo-news", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "server.js", "max_issues_repo_name": "jeffreylowy/mongo-news", "max_issues_repo_issues_event_min_datetime": "2018-01-06T02:24:21.000Z", "max_issues_repo_issues_event_max_datetime": "2018-01-06T02:24:21.000Z", "max_forks_repo_path": "server.js", "max_forks_repo_name": "jeffreylowy/mongo-news", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": 1, "max_forks_count": null, "avg_line_length": 26.85, "max_line_length": 94, "alphanum_fraction": 0.7076350093}
require("dotenv").config();
const express = require('express');
const exphbs = require('express-handlebars');
const bodyParser = require('body-parser');
const mongoose = require('mongoose');
const routes = require('./routes');
// Fallback to local DB when MONGODB_URI does not exist (basically anything outside of Heroju)
const dbURL = process.env.MONGODB_URI || 'mongodb://localhost/gamespot';
const PORT = process.env.PORT || 3000;
const app = express();

// Basix Express setup
app.engine('.hbs', exphbs({
	defaultLayout: 'main',
	extname: '.hbs'
}));
app.set('view engine', '.hbs');
app.use(express.static("public"));
app.use(bodyParser.urlencoded({
	extended: false
}));
app.use(bodyParser.json());

// Load the app's routes
app.use("/", routes);

// Connect to MongoDB
mongoose.connect(dbURL);
let db = mongoose.connection;

// Display any database errors
db.on("error", function (error) {
	console.log(error);
});

// Start the server when successfully connected to the database
db.on("open", function () {
	console.log("Connected to MongoDB");
	app.listen(PORT);
});