-
Notifications
You must be signed in to change notification settings - Fork 4
/
app.js
41 lines (29 loc) · 928 Bytes
/
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
var express = require('express');
var bodyParser = require('body-parser');
var mongoose = require('mongoose');
var validator = require('express-validator'); // Express Validator
var config = require('./config');
var logger = require('./lib/logger');
var router = require('./routes');
var app = express();
// Start Server
app.listen(config.HTTP_PORT, function connectionListener(){
console.log('API Server running on ', config.HTTP_PORT);
});
//Connect to MongoDB
mongoose.connect(config.MongoURL, function(err, data){
if(err) {
console.log('Error connecting to DB');
console.log(err);
} else {
console.log("App is connected to DB");
}
});
// This will log http methods and url
app.use(logger());
// Parser JSON body Requests
app.use(bodyParser.json());
// We will use the validator after the bodyParser
app.use(validator());
// Pass app to router
router(app);