-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
39 lines (32 loc) · 915 Bytes
/
app.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
const express = require("express");
const bodyParser = require("body-parser");
const db = require("./utils/dbConnect");
const userRoute = require("./routes/userRoute");
const productRoute = require("./routes/productRoute");
const orderRoute = require("./routes/orderRoute");
// Model
const User = require("./models/userModel");
const app = express();
// app middleware
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
// get user detail middleware
app.use((req, res, next) => {
User.fetchSingleUser("63392705352ae332551a6a42")
.then((user) => {
req.user = user;
next();
})
.catch((err) => {
throw err;
});
});
// custom Middlewares
app.use("/user", userRoute);
app.use("/product", productRoute);
app.use("/order", orderRoute);
db.dbConnection(() => {
app.listen(5000, () => {
console.log("MongoConnect & Server is Running");
});
});