-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathserver.js
49 lines (37 loc) · 1.11 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
//this is the server file//
const express = require('express');
const mongoose = require('mongoose');
const bodyParser = require('body-parser');
const morgan = require('morgan');
const passport = require('passport');
const config = require('./config/main');
const users = require('./routes/users');
const routines = require('./routes/routines');
const PORT = process.env.PORT || 5000;
const app = express();
/********* Body-parser config **********/
app.use(
bodyParser.urlencoded({
extended: false,
})
);
app.use(bodyParser.json());
// Log requests to console
app.use(morgan('dev'));
// Initialize passport
app.use(passport.initialize());
// Database Config
mongoose
.connect(config.database)
.then(() => console.log('MongoDB connected'))
.catch(err => {
throw new Error(err);
});
// Bring in the passport strategy we defined
require('./config/passport')(passport);
/********* Routes **********/
// Append user routes from user.js to /api/users
app.use('/api/users/', users);
app.use('/api/routines/', routines);
app.listen(PORT, () => console.log(`Server up and running on port ${PORT}`));
module.exports = app;