-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
49 lines (40 loc) · 1.18 KB
/
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
47
48
49
const express = require("express");
const dotenv = require("dotenv");
const colors = require("colors");
const morgan = require("morgan");
const cors = require("cors");
const connectDB = require("./config/db");
const path = require ("path");
//dot config
dotenv.config();
//mongodb connection -->after dotenv function always
connectDB();
//rest object
const app = express();
//middlewares
app.use(express.json());
app.use(cors());
app.use(morgan("dev"));
//routes
//1 test route
//test route
app.use("/api/v1/test", require("./routes/testRoutes"));
app.use("/api/v1/auth",require("./routes/authRoutes"));
app.use("/api/v1/inventory",require("./routes/inventoryRoutes"));
app.use("/api/v1/analytics",require("./routes/analyticsRoutes"));
app.use("/api/v1/admin",require("./routes/adminRoutes"));
//STatic Folder
app.use(express.static(path.join(__dirname,"./client/build")))
// Static Routes
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(
`Node Server is running in ${process.env.DEV_MODE} Mode On port ${process.env.PORT}`
.bgBlue.white
);
});