-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
49 lines (39 loc) · 1.2 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
const express = require("express");
const bodyParser = require("body-parser");
const mongoose = require("mongoose");
const passport = require("passport");
//importing routes
const authjs = require("./routes/api/auth");
const profile = require("./routes/api/profile");
const question = require("./routes/api/question");
const answer = require("./routes/api/answer");
//importing
const utilsMongoose = require("./utils/mongoose");
const app = express();
const PORT = process.env.PORT || 8000;
//connecting mongoDB
mongoose
.connect(utilsMongoose.urlOfMonogDb, { useNewUrlParser: true })
.then(() => {
console.log(`connected to DB`);
})
.catch(err => console.log(err));
//initialize the passport
app.use(passport.initialize());
//importing JWT startegy
require("./strategies/jwtStrategy")(passport);
//using bodyparser for parsing incoming request body
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
//using routes
app.use("/api/auth", authjs);
app.use("/api/profile", profile);
app.use("/api/question", question);
app.use("/api/answer", answer);
//listing to the port
app.listen(PORT, err => {
if (err) {
throw err;
}
console.log(`server is running at ${PORT}`);
});