-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
29 lines (25 loc) · 957 Bytes
/
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
const express = require('express'),
path = require('path'),
bodyParser = require('body-parser'),
cors = require('cors'),
mongoose = require('mongoose'),
config = require('./config/DB');
traineeRoutes = require('./expressRoutes/traineeRoutes');
listRoutes = require('./expressRoutes/listRoutes');
sessionRoutes = require('./expressRoutes/sessionRoutes');
//using Promises here, convert to observable when possible @dnilasor
mongoose.Promise = global.Promise;
mongoose.connect(config.DB).then(
() => {console.log('Database is connected') },
err => { console.log('Can not connect to the database'+ err)}
);
const app = express();
app.use(bodyParser.json());
app.use(cors());
const port = process.env.PORT || 4000;
app.use('/trainees', traineeRoutes);
app.use('/lists', listRoutes);
app.use('/sessions', sessionRoutes);
const server = app.listen(port, function () {
console.log('Listening on port ' + port);
});