-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
50 lines (43 loc) · 1.44 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
require("dotenv").config();
const mongoose = require("mongoose");
const express = require("express");
const app = express();
var bodyParser = require("body-parser");
// cookie-parser helps us to create or put some values to the cookies or delete some value from cookies
var cookieParser = require("cookie-parser");
var cors = require("cors");
// My Routes
const authRoutes = require("./routes/auth");
const userRoutes = require("./routes/user");
const categoryRoutes = require("./routes/category");
const productRoutes = require("./routes/product");
const orderRoutes = require("./routes/order");
const paymentBraintreeRoutes = require("./routes/paymentBraintreeRoutes");
mongoose
.connect(process.env.DATABASE_URI, {
useNewUrlParser: true, // This is compulory
useUnifiedTopology: true, // It helps us keep our database connection alive
useCreateIndex: true, // You can read about all these more in mongoose docs
})
.then(() => {
console.log("DB CONNECTED!");
})
.catch(() => {
console.log("DB CONNECTION FAILED!");
});
// Middleware
app.use(bodyParser.json());
app.use(cookieParser());
app.use(cors());
// My Routes
app.use("/api", authRoutes);
app.use("/api", userRoutes);
app.use("/api", categoryRoutes);
app.use("/api", productRoutes);
app.use("/api", orderRoutes);
app.use("/api", paymentBraintreeRoutes);
// PORT
const port = process.env.PORT || 1337;
app.listen(port, () => {
console.log(`App is running at ${port}`);
});