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