forked from BTP-Project-Semester-4/Loco-Cart-Backend
-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
59 lines (56 loc) · 2.26 KB
/
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// DECLARING MODULES
const express = require("express");
const cors = require("cors");
const mongoose = require("mongoose");
const env = require("dotenv");
const http = require("http");
const bodyParser = require("body-parser");
const sellerRoute = require("./router/SellerRouter.js");
const customerRoute = require("./router/CustomerRouter.js");
const sellerProductRoute = require("./router/SellerProducts.js");
const sellerPastOrderRoute = require("./router/SellerPastOrder.js");
const customerPastOrderRouter = require("./router/CustomerPastOrder.js");
const categoryProductRouter = require("./router/CategoryProducts.js");
const product = require("./router/Product.js");
const applicationRunning = require("./router/api.js");
const reviewAndComments = require("./router/ReviewAndComments.js");
const feedbackRouter = require("./router/Feedbacks.js");
const biddingRouter = require("./router/BiddingRouter");
const notificationRouter = require("./router/NotificationRouter.js");
//DEFINING MODULES
const app = express();
const port = 3001 || process.env.PORT;
const hostname = "localhost";
//VALIDATING MODULES POLICY
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
app.use(cors());
env.config();
//CONNECTING MONGO DB
const url = process.env.MONGODB;
mongoose.connect(`${url}`, {
useNewUrlParser: true,
useUnifiedTopology: true,
useCreateIndex: true,
});
const connection = mongoose.connection;
connection.once("open", () => {
console.log("MongoDB database connection established successfully");
});
// SENDING TO ROUTES
app.use("/api", applicationRunning);
app.use("/api/seller", sellerRoute);
app.use("/api/customer", customerRoute);
app.use("/api/seller_product", sellerProductRoute);
app.use("/api/sellerpastorder", sellerPastOrderRoute);
app.use("/api/customerpastorder", customerPastOrderRouter);
app.use("/api/categoryproducts", categoryProductRouter);
app.use("/api/product", product);
app.use("/api/reviewandcomment", reviewAndComments);
app.use("/api/feedback", feedbackRouter);
app.use("/api/bid", biddingRouter);
app.use("/api/notification", notificationRouter);
//STARTING APP
app.listen(process.env.PORT || 3001, () => {
console.log(`Server Running at http://${hostname}:${port}/`);
});