-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
55 lines (44 loc) · 1.22 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
52
53
54
55
import express from "express";
import dotevn from "dotenv";
import mongoose from "mongoose";
//routes
import authRoute from './routes/auth.js'
import usersRoute from './routes/users.js'
import roomsRoute from './routes/rooms.js'
import hotelsRoute from './routes/hotels.js'
const app = express()
dotevn.config()
const connect = async() => {
try {
await mongoose.connect(process.env.MONGO)
console.log("connected to mongo db")
} catch (error) {
throw error
}
}
mongoose.connection.on("disconnected", () => {
console.log("Mongo DB disconnected")
})
mongoose.connection.on("connected", () => {
console.log("Mongo DB connected")
})
//middelwares
app.use(express.json())
app.use("/api/auth", authRoute);
app.use("/api/users", usersRoute);
app.use("/api/roooms", roomsRoute);
app.use("/api/hotels", hotelsRoute);
app.use((err, rep, res, next) => {
const errorSatus = err.status || 500
const errorMessage = err.message || "Something went wrong!";
return res.status(errorSatus).json({
success: false,
message: errorMessage,
status: errorSatus,
stack: err.stack
})
})
app.listen(8800, () => {
connect()
console.log("connected to backend!")
})