-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
40 lines (29 loc) · 902 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
35
36
37
38
39
40
require("dotenv").config();
const express = require("express");
const cors = require("cors");
const app = express();
app.use(cors());
app.use(express.json());
const mongoose = require("mongoose");
const source = process.env.ATLAS_CONNECTION;
mongoose.connect(source, {
useNewUrlParser: true,
useCreateIndex: true,
useUnifiedTopology: true
});
const connection = mongoose.connection;
connection.once("open", () => {
console.log("DB connected");
});
// routes
const userRoutes = require("./controllers/UserController");
app.use("/users", userRoutes);
const path = require("path");
app.use(express.static(path.join(__dirname, "client", "build")));
app.get("*", (req, res) => {
res.sendFile(path.join(__dirname, "client", "build", "index.html"));
});
const PORT = process.env.PORT || 8000;
app.listen(PORT, () => {
console.log("Server is running on http://localhost:" + PORT);
});