-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
37 lines (32 loc) · 910 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
37
// CREATING AN API
// IMPORTS FROM PACKAGES
const express = require("express");
const mongoose = require("mongoose");
// IMPORTS FROM FILES
const authRouter = require("./routes/auth");
const productRouter = require("./routes/product");
const adminRouter = require("./routes/admin");
const userRouter = require("./routes/user");
// INITIALIZE
const PORT = process.env.PORT || 3000;
const app = express();
const DB =
"mongodb+srv://secondadmin:[email protected]/?retryWrites=true&w=majority";
// MIDDLEWARE
app.use(express.json());
app.use(authRouter);
app.use(adminRouter);
app.use(productRouter);
app.use(userRouter);
// CONNECTION
mongoose
.connect(DB)
.then(() => {
console.log("Connection to the database has been established");
})
.catch((e) => {
console.log(e);
});
app.listen(PORT, "0.0.0.0", function () {
console.log(`CONNECTED AT PORT: ${PORT}`);
});