-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
36 lines (31 loc) · 937 Bytes
/
index.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
const express = require("express");
const cors = require("cors");
const app = express();
const mongoose = require("mongoose");
require("dotenv").config();
//applying middleware
app.use(express.json());
app.use(cors());
//mongodb connection
mongoose
.connect(process.env.MONGODB, {
useNewUrlParser: true,
useUnifiedTopology: true,
})
.then(() => console.log("connected"))
.catch((err) => console.log("err:", err));
//routes and requring controllers
const userRoute = require("./routes/userRouter");
const authUser = require("./routes/authUser");
const products = require("./routes/products");
const carts = require("./routes/cartRoutes");
const orders = require("./routes/orderRoutes");
app.use("/api", userRoute);
app.use("/api", authUser);
app.use("/api", products);
app.use("/api", carts);
app.use("/api", orders);
//port listening
app.listen(process.env.PORT || 5000, () => {
console.log("server running");
});