-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.js
35 lines (34 loc) · 1.4 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
/* Server Dependencies */
const express = require("express"); //Load ExpressJS
const routes = require("./routes"); //Load Routes from folder
const mongoose = require('mongoose') //Load Mongoose for MongoDB
//Express Configuration
const path = require("path");
const PORT = process.env.PORT || 8000; //Run Server on Port 3001
const app = express(); //Init Express to app
// Define middleware
//require("dotenv").config(); // Read and set environment variables
app.use(express.urlencoded({ extended: true }));
app.use(express.json());
// Serve up static assets
if (process.env.NODE_ENV === "production") {
app.use(express.static("client/build"));
}
// Define API routes here
// Add routes, both API, view, and Auth Routes
app.use(routes);
// Define any API routes before this runs
// app.get("*", (req, res) => {
// res.sendFile(path.join(__dirname, "./client/build/index.html"));
// });
/* ---------------Startup Sequence--------------- */
console.log("-----------Startup log------------\n")
//Connect to MongoDB then startup server
mongoose.connect('mongodb+srv://admin:[email protected]/halfway?retryWrites=true&w=majority', () => {
console.log('\n\n====> Connected to MongoDB <====\n\n')
//Set server to start Listening
app.listen(PORT, () => {
console.log(`====> API server now running on port ${PORT} <====` + "\n\n");
console.log("-----------End of Startup log------------\n")
});
})