-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathindex.js
More file actions
41 lines (32 loc) · 1.11 KB
/
Copy pathindex.js
File metadata and controls
41 lines (32 loc) · 1.11 KB
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
import dotenv from "dotenv";
import express from "express";
import mongoose from "mongoose";
import listingRoutes from "./routes/listing.route.js";
import userRoutes from './routes/users.route.js';
import searchRoutes from './routes/search.router.js';
import bookingsRoutes from './routes/bookings.router.js';
import errorHandler from "./utils/errorHandler.js";
// Load environment variables
dotenv.config();
const app = express();
const URL =
process.env.MONGO_URL ||
"mongodb+srv://teamfeammearn:IchwrnfkrNZ7Jark@cluster0.0xq8q.mongodb.net/AIRNBN?retryWrites=true&w=majority";
// Connect to MongoDB
mongoose
.connect(URL)
.then(() => console.log("Connected to DB successfully"))
.catch((err) => console.log("Failed to connect to DB:", err));
app.use(express.json());
// Error handling middleware
app.use(express.json());
app.use(errorHandler);
// Routes
app.use("/listing", listingRoutes);
app.use('/user', userRoutes)
app.use('/search', searchRoutes)
app.use('/booking', bookingsRoutes)
const port = process.env.PORT || 4000;
app.listen(port, () => {
console.log(`Server is running on http://localhost:${port}`);
});