-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
44 lines (34 loc) · 1.14 KB
/
server.js
File metadata and controls
44 lines (34 loc) · 1.14 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
42
43
44
require("dotenv").config();
const express = require("express");
const mongoose = require("mongoose");
const path = require("path");
const app = express();
const PORT = process.env.PORT || 5000;
// Debugging log to check MONGO_URI
console.log("MongoDB URI:", process.env.MONGO_URI);
// Init Middleware
app.use(express.json({ extended: false }));
async function main() {
if (!process.env.MONGO_URI) {
throw new Error("MONGO_URI is not defined in the environment variables.");
}
await mongoose.connect(process.env.MONGO_URI, {
useNewUrlParser: true,
useUnifiedTopology: true,
});
console.log("Connected to MongoDB");
}
main().catch(err => console.error("MongoDB Connection Error:", err));
app.use(express.static(path.join(__dirname, "VIEWS")));
app.use(express.static(path.join(__dirname, "Public")));
// Define Routes
app.use('/api/auth', require('./routes/auth'));
app.get("/", (req, res) => {
res.send("App Is working");
});
app.get("/home", (req, res) => {
res.sendFile(path.join(__dirname, "VIEWS", "E-learning.html"));
});
app.listen(PORT, () => {
console.log(`App is listening on port ${PORT}`);
});