-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
30 lines (26 loc) · 939 Bytes
/
server.js
File metadata and controls
30 lines (26 loc) · 939 Bytes
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
require("dotenv").config();
const express = require("express");
const mongoose = require("mongoose");
const cors = require("cors");
const userRoutes = require("./routes/userRoutes");
const app = express();
app.use(cors()); // ← تسمح بالتواصل بين صفحات HTML وخادم Express
app.use(express.json());
// هذا السطر هو المهم لحل مشكلة Cannot GET /
app.get("/", (req, res) => {
res.send("Welcome to the Mongoose Demo API 🚀");
});
// المسارات الخاصة بالمستخدمين
app.use("/users", userRoutes);
// الاتصال بقاعدة البيانات
mongoose
.connect(process.env.MONGO_URI)
.then(() => {
console.log("✅ Connected to MongoDB");
app.listen(process.env.PORT, () => {
console.log(
`🚀 Server is running at http://localhost:${process.env.PORT}`
);
});
})
.catch((err) => console.error("❌ Connection error:", err));