-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
50 lines (43 loc) · 1.12 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
50
import express from "express";
import colors from "colors";
import dotenv from "dotenv";
import morgan from "morgan";
import connectDB from "./config/db.js";
import authRoutes from "./routes/authRouter.js";
import categoryRoutes from "./routes/categoryRouter.js";
import productRoutes from "./routes/productRouter.js";
// import paymentRoutes from "./routes/paymentRouter.js";
import cors from "cors";
//configure env
dotenv.config();
//database config
connectDB();
//rest object
const app = express();
//middlewares
app.use(cors());
app.use(express.json());
app.use(morgan("dev"));
//routes
app.use("/auth", authRoutes);
app.use("/category", categoryRoutes);
app.use("/product", productRoutes);
// app.use("/payment", paymentRoutes);
//rest api
app.get("/", (req, res) => {
res.send({
message: "server is running"
});
});
app.use((err, req, res, next) => {
console.error(err.stack);
res.status(500).send('Internal Server Error');
});
//PORT
const PORT = process.env.PORT || 5000;
//run listen
app.listen(PORT, () => {
console.log(
`Server Running on ${process.env.DEV_MODE} mode on port ${PORT}`.bgBlue.white.bold
);
});