-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
46 lines (37 loc) · 1010 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
41
42
43
44
45
46
const express = require("express");
const cors = require("cors");
const morgan = require("morgan");
const colors = require("colors");
const dotenv = require("dotenv");
const connectDB = require("./config/db");
const path = require('path')
//env config
dotenv.config();
//router import
const userRoutes = require("./routes/userRoutes");
const blogRoutes = require("./routes/blogRoutes");
//mongodb connection
connectDB();
//rest objecct
const app = express();
//middelwares
app.use(cors());
app.use(express.json());
app.use(morgan("dev"));
//routes
app.use("/api/v1/user", userRoutes);
app.use("/api/v1/blog", blogRoutes);
//static files
app.use(express.static(path.join(__dirname, './client/build')))
app.get('*', function (req, res) {
res.sendFile(path.join(__dirname, './client/build/index.html'));
});
// Port
const PORT = process.env.PORT || 8080;
//listen
app.listen(PORT, () => {
console.log(
`Server Running on ${process.env.DEV_MODE} mode port no ${PORT}`.bgCyan
.white
);
});