-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
41 lines (34 loc) · 1.25 KB
/
server.js
File metadata and controls
41 lines (34 loc) · 1.25 KB
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
const mongoose = require("mongoose");
const express = require("express");
var cors = require("cors");
require("dotenv").config();
const logger = require("morgan");
const Data = require("./data");
const path = require("path");
const app = express();
app.use(cors());
app.use(express.json());
const APP_PORT = process.env.PORT || 5000;
const DB_URI =
process.env.DB_URI ||
"mongodb+srv://fullstack_app:123456Asd@cluster0-pz6hc.mongodb.net/test?retryWrites=true&w=majority";
/* MangoeDB Conecation */
mongoose.connect(DB_URI, { useNewUrlParser: true, useCreateIndex: true });
const connection = mongoose.connection;
connection.once("open", () => {
console.log("MongoDB database connection established successfully");
});
// ... other app.use middleware
app.use(express.static(path.join(__dirname, "client", "build")));
// ...
// // Right before your app.listen(), add this:
// app.get("*", (req, res) => {
// res.sendFile(path.join(__dirname, "client", "build", "index.html"));
// });
/* Routes */
const usersRoutes = require("./routes/users");
const exerciseRoutes = require("./routes/exercise");
app.use("/exercises", exerciseRoutes);
app.use("/users", usersRoutes);
// launch our backend into a port
app.listen(APP_PORT, () => console.log(`LISTENING ON PORT ${APP_PORT}`));