-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
55 lines (44 loc) · 1.34 KB
/
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
const express = require("express");
const app = express();
const bodyParser = require("body-parser");
const mongoose = require("mongoose");
const dotenv = require("dotenv");
const cors = require("cors");
//Middleware
const errorHandler = require("./middlewares/error");
//Routes
const studentAuth = require("./routes/studentAuth");
const assignStudent = require("./routes/assignStudent");
const teacherAuth = require("./routes/teacherAuth");
const assignTeacher = require("./routes/assignTeacher");
const attendance = require("./routes/attendance");
const courses = require("./routes/course");
dotenv.config();
const db = process.env.MONGO_URI;
console.log(db, "db");
mongoose
.connect(db, {
useNewUrlParser: true,
useUnifiedTopology: true,
useCreateIndex: true,
})
.then(() => {
console.log("Database connected");
})
.catch((err) => {
console.log("Error connecting to the database", err);
});
app.use(bodyParser.json());
app.use(cors());
//Defining routes
app.use("/student", studentAuth);
app.use("/student", assignStudent);
app.use("/teacher", teacherAuth);
app.use("/teacher", assignTeacher);
app.use("/attendance",attendance);
app.use("/course",courses);
app.use(errorHandler);
const PORT = process.env.PORT || 5000;
app.listen(PORT, () => {
console.log(`Server started on PORT ${PORT}`);
});