-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
36 lines (30 loc) · 809 Bytes
/
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
const express = require("express");
require("dotenv").config();
const AuthRouter = require("./routes/auth");
const ConnectDB = require("./db/connect");
const app = express(); //initialize the app()
//middleware
app.use(express.json());
//middlewares
//env variables
const PORT = process.env.PORT;
var connectionString = process.env.MONGO_URI;
//env variables
//routes
app.use("/api/v1/", AuthRouter);
//routes
//connect to db and then start the server if connection Successful
const start = async () => {
try {
await ConnectDB(connectionString);
console.log("Db connected Successfully");
//start the server
app.listen(PORT, () => {
console.log(`Listening on port ${PORT}`);
});
} catch (err) {
console.log(err);
res.status(500).json({ msg: `Something Went Wrong!!` });
}
};
start();