-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
30 lines (27 loc) · 848 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
const http = require("http");
const express = require("express");
const mongoose = require("mongoose");
const bodyParser = require("body-parser");
const cors = require("cors");
mongoose
.connect(process.env.MONGODB_URI || "mongodb://localhost:27017/Chat_Go", {
useNewUrlParser: true,
useUnifiedTopology: true,
})
.then(() => console.log("MongoDB Connected..."))
.catch((err) => console.log(err));
const app = express();
app.use(cors());
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
const PORT = process.env.PORT || 5000;
if (process.env.NODE_ENV === "production") {
app.use(express.static("client/build"));
}
app.get("/", (req, res) => {
res.send("Hello");
});
const server = http.createServer(app);
server.listen(PORT, () => {
console.log(`server is running on localhost:${PORT}`);
});