{"size": 1268, "ext": "js", "max_stars_repo_path": "api/src/server.js", "max_stars_repo_name": "alanxie29/subscription-bot", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "api/src/server.js", "max_issues_repo_name": "alanxie29/subscription-bot", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "api/src/server.js", "max_forks_repo_name": "alanxie29/subscription-bot", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 28.1777777778, "max_line_length": 89, "alphanum_fraction": 0.6932176656}
var express = require('express');
var bodyParser = require('body-parser');
var passport = require('passport');
var mongoose = require('mongoose');
var config = require('./config/config');
var port = process.env.PORT || 5000;
var cors = require('cors');

var app = express();
app.use(cors());

// get our request params
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());

// use passport package in application
app.use(passport.initialize());
var passportMiddleware = require('./middleware/passport');
passport.use(passportMiddleware);

// demo route (GET http://localhost:5000)
app.get('/', function(req, res) {
    return res.send('Hello! The API is at http://localhost:' + port + '/api');
});

var routes = require('./routes');
app.use('/api', ProtectedRoutes);
app.use('', routes)

mongoose.connect(config.db, { useNewUrlParser: true, useCreateIndex: true});

const connection = mongoose.connection;

connection.once('open', () => {
    console.log('MongoDB database connection established successfully!');
});

connection.on('error', (err) => {
    console.log("MongoDB connection error. Please make sure MongoDB is running. " + err);
    process.exit();
});

// start server
app.listen(port);
console.log('http://localhost:' + port);