-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
57 lines (50 loc) · 1.42 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
56
57
/**
* import the library
*/
const express = require("express");
const bodyParser = require("body-parser");
/**
* import the routes file
*/
const authRoute = require("./routes/auth");
const userRoute = require("./routes/users");
const postRoute = require("./routes/posts");
const questionRoute = require("./routes/questions");
const examRoute = require("./routes/exam");
const categoryRoute = require("./routes/category");
/**
* import some essential file
*/
const { DB } = require("./helpers/DB.js");
const { SERVER_PORT } = require("./config.js");
const { skills } = require("./dummy.js"); // for dummy data
const auth = require("./middleware/auth");
// Creating the app
const app = express();
// Creating the database connection
DB.ConnectDB();
/**
* Setting the middleware
*/
// static folder
app.use(express.static("public"));
// parse application/x-www-form-urlencoded
app.use(bodyParser.urlencoded({ extended: false }));
// parse application/json
app.use(bodyParser.json());
/**
* Setting the routes
*/
app.use("/api/auth", authRoute);
app.use("/api/users", userRoute);
app.use("/api/posts", postRoute);
app.use("/api/questions", questionRoute);
app.use("/api/exam", examRoute);
app.use("/api/category", categoryRoute);
app.get("/api/skills", auth, function (req, res) {
res.send(skills);
});
const PORT = process.env.PORT || SERVER_PORT;
app.listen(PORT, function () {
console.log(`Server is running on port ${PORT}`);
});