-
Notifications
You must be signed in to change notification settings - Fork 3
/
server.js
41 lines (30 loc) · 1.24 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
// Pulls in our required dependencies.
const express = require("express");
const mongoose = require("mongoose");
const bodyParser = require("body-parser");
const passport = require("passport");
const routes = require("./routes");
require("dotenv").config();
// Initializes the application using the express dependency.
const app = express();
// Applies the middleware function.
app.use(bodyParser.urlencoded({ extended: false }));
if (process.env.NODE_ENV === "production") {
app.use(express.static("client/build"));
}
app.use(bodyParser.json());
// Database configuration.
const db = require("./config/keys");
// MongoDB connection using the mongoose dependency.
mongoose.connect(process.env.MONGODB_URI || "mongodb://localhost/covidtracker", { useNewUrlParser: true, useUnifiedTopology: true }).then (() => console.log("Successfully made connection to MongoDB."))
.catch(err => console.log(err));
// Passport middleware.
app.use(passport.initialize());
// Passport configuration.
require("./config/passport")(passport);
// Routes
app.use(routes);
// Sets the port for the server to run on.
const PORT = process.env.PORT || 5000;
// The application is listening in on the port.
app.listen(PORT, () => console.log("Server is up and running on PORT 5000."));