-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
37 lines (31 loc) · 860 Bytes
/
server.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
const express = require("express");
const cors = require("cors");
const mongoose = require("mongoose");
const { json } = require("express");
const userRoutes = require("./routes/UserRoutes");
require('dotenv').config();
const app = express();
app.use(cors());
app.use(json());
// MongoDB connection
mongoose
.connect(process.env.MONGODB_URI, {
useNewUrlParser: true,
useUnifiedTopology: true,
})
.then(() => {
console.log("DB Connection Successful");
})
.catch((err) => {
console.error("Error connecting to DB:", err.message);
});
app.use("/api/user", userRoutes);
// Health check endpoint
app.get("/health", (req, res) => {
res.status(200).json({ message: "Server is healthy" });
});
// Port configuration
const PORT = process.env.PORT || 5000;
app.listen(PORT, () => {
console.log(`Server started on port ${PORT}`);
});