-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
44 lines (35 loc) · 1.07 KB
/
app.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
require("dotenv").config();
const express = require("express");
const app = express();
const port = 5500;
const cors = require("cors");
app.use(cors());
// db connection
const dbConnection = require("./db/dbConfig");
// app.get('/', (req, res)=>{
// res.send('welcome')
// })
// user routes middleware file
const userRoutes = require("./routes/userRouts");
const questionRoutes = require("./routes/questionRouter");
// authMiddleweare
const authMiddleware = require("./middleweare/authMiddleware");
const answerRouter = require("./routes/answerRouter");
// jeson middlewear to extract json data
app.use(express.json());
// user routes middleware
app.use("/api/users", userRoutes);
// question routes middleware
app.use("/api/questions", authMiddleware, questionRoutes);
// answer routes middleware
app.use("/api/answer", authMiddleware, answerRouter);
async function start() {
try {
const result = await dbConnection.execute("select 'test' ");
await app.listen(port);
console.log(`listening on ${port}`);
} catch (error) {
console.log(error.message);
}
}
start();