-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
50 lines (35 loc) · 1.27 KB
/
index.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
const express = require('express');
const mongoose = require('mongoose');
const bodyparser = require('body-parser');
const passport = require('passport');
const port = process.env.PORT || 3000;
//get all routes
const auth = require('./routes/api/auth.js');
const question = require('./routes/api/question');
const profile = require('./routes/api/profile');
const app = express();
//MIDDLEWARE FOR BODY-PARSER
app.use(bodyparser.urlencoded({extended: false}));
app.use(bodyparser.json());
//mongoDB configuration
const db = require('./setup/myurl').mongoURL //setup in myurl
//CONNECTION TO mongoDB
mongoose
.connect(db) //don't put semicolon
.then(() => console.log('MongoDB connected suuccessfully')) //don't put semicolon
.catch(err => {
return console.log(err);
});
//PASSPORT MIDDLEWARE
app.use(passport.initialize());
//CONFIG FOR JWT strategy
require('./strategies/jsonWTStrategy')(passport)
//route for testing purpose
// app.get('/', (req,res) => {
// res.send('Hey there Big stack')
// });
//ACTUAL ROUTES
app.use('/api/auth', auth);
app.use('/api/questions', question);
app.use('/api/profile',profile);
app.listen(port, () =>console.log(`APP IS RUNNING ON ${port}`));