-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
27 lines (19 loc) · 824 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
require('dotenv').config();
const express = require('express');
const mongoose = require('mongoose');
const app = express();
const { userRouter } = require('./routes/user');
const { courseRouter } = require('./routes/course');
const { adminRouter } = require('./routes/admin');
app.use(express.json());
app.use("/api/v1/user" , userRouter);
app.use('/api/v1/admin' , adminRouter);
app.use("/api/v1/course" , courseRouter);
// If the database connection failed so there is no sense to start our backend.
// So in this case we need to ensure that our backend doesn't gets started until its not connected to the database!
async function main() {
await mongoose.connect(process.env.MONGO_URL);
app.listen(process.env.PORT);
console.log("Database Connection Successfully Established!, Good TO go!");
}
main();