-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
40 lines (34 loc) · 1.2 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
/*
====================== PLEASE ADD YOUR CHANGE DESCRIPTIONS HERE ==============
28-09-2020 - Manoj Created Index.js
07-10-2020 - added mongodb connection & booking route, added secrets.json
*/
const express = require("express");
const sltbApi = express();
const mongoose = require("mongoose");
const PORT = 5000 || process.env.PORT;
const secrets = require("./secrets.json");
const dbName = "sltb_api_db";
sltbApi.use(express.json());
//Define Routes
const bookingRoute = require("./components/booking/BookingRoutes");
const transitNodeRoute = require("./components/places/routes/transitNodeRoutes");
const userRoutes = require("./components/user/routes/UserRoutes");
//Use Routes
sltbApi.use("/api/booking", bookingRoute);
sltbApi.use('/api/transit/nodes', transitNodeRoute)
sltbApi.use('/api/users', userRoutes)
//db connection
mongoose
.connect(
`mongodb+srv://${secrets.mongousername}:${secrets.mongopass}@${secrets.mongourl}/${dbName}`)
.then(() => {
console.log("Connected to MongoDB Cloud");
})
.catch((e) => {
console.log(e);
console.log("Connection to MongoDB Cloud Failed");
});
sltbApi.listen(PORT, () => {
console.log(`Server Has Started working on port ${PORT}`);
});