-
Notifications
You must be signed in to change notification settings - Fork 40
/
index.js
51 lines (42 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
40
41
42
43
44
45
46
47
48
49
50
51
const cors = require("cors");
const exp = require("express");
const bp = require("body-parser");
const passport = require("passport");
const { connect } = require("mongoose");
const { success, error } = require("consola");
// Bring in the app constants
const { DB, PORT } = require("./config");
// Initialize the application
const app = exp();
// Middlewares
app.use(cors());
app.use(bp.json());
app.use(passport.initialize());
require("./middlewares/passport")(passport);
// User Router Middleware
app.use("/api/users", require("./routes/users"));
const startApp = async () => {
try {
// Connection With DB
await connect(DB, {
useFindAndModify: true,
useUnifiedTopology: true,
useNewUrlParser: true
});
success({
message: `Successfully connected with the Database \n${DB}`,
badge: true
});
// Start Listenting for the server on PORT
app.listen(PORT, () =>
success({ message: `Server started on PORT ${PORT}`, badge: true })
);
} catch (err) {
error({
message: `Unable to connect with Database \n${err}`,
badge: true
});
startApp();
}
};
startApp();