-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
39 lines (32 loc) · 1.13 KB
/
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
37
38
39
const express = require("express");
const app = express();
const morgan = require("morgan");
const helmet = require("helmet");
const mongoose = require("mongoose");
const dotenv = require("dotenv");
const port = process.env.PORT || "8800";
const userRoutes = require("./routes/user.js");
const authRoutes = require("./routes/auth");
const productRoutes = require("./routes/product");
const orderRoutes = require("./routes/order");
const cartRoutes = require("./routes/cart");
dotenv.config();
mongoose.connect(process.env.MONGO_URL, { useNewUrlParser: true, useUnifiedTopology: true })
.then(() => {
console.log("Successfully Connected to MongoDB")
})
.catch((err) => {
console.log("This error is coming when we try to connect with MongoDB : \n" + err);
});
app.use(express.json());
app.use(helmet());
app.use(morgan("common"));
//routes middleware
app.use("/api/users", userRoutes);
app.use("/api/auth", authRoutes);
app.use("/api/products", productRoutes);
app.use("/api/carts", cartRoutes);
app.use("/api/orders", orderRoutes);
app.listen(port, () => {
console.log("App is listening at localhost:" + port);
});