-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathserver.js
34 lines (27 loc) · 1021 Bytes
/
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
const express = require("express");
const path = require("path");
const mongoose = require("mongoose");
require("dotenv").config();
const config = require("./config");
const routes = require("./routes");
const app = express();
// middleware to parse data
app.use(express.urlencoded({ extended: true }))
app.use(express.json())
// serve up static assets
// if (process.env.NODE_ENV === "production") {
// app.use(express.static(path.join(__dirname, "./client/build")))
// };
app.use(express.static(path.join(__dirname, "./client/build")))
// connect to Mongo DB
mongoose.connect(config.MONGO_URI, { useNewUrlParser: true, useUnifiedTopology: true, useCreateIndex: true, useFindAndModify: true })
.then(() => console.log(`Mongo DB Succesfully Connected`))
.catch(err => console.log(err));
// use routes
app.use(routes);
// check for "production" enviroment and set port
const PORT = process.env.PORT || 3001;
// start server
app.listen(PORT, () => {
console.log(`App listening on port: ${PORT}`);
})