-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
39 lines (33 loc) · 899 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
30
31
32
33
34
35
36
37
38
39
/**
* Get all our dependencies
*/
var express = require('express'),
bodyParser = require('body-parser'),
morgan = require('morgan'),
mongoose = require('mongoose'),
conf = require('./config');
/**
* Connect & configure
*/
var app = express();
var port = conf.server.port;
mongoose.connect(conf.database.url, function(err) {
if (err) {
console.log('connection error', err);
} else {
console.log('connection successful');
}
});
// use body parser to easily read requests
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
// use morgan to log requests to the console
app.use(morgan('dev'));
// set up routes
require('./routes')(app);
/**
* Start the server
*/
if(!module.parent){ app.listen(port); } // wrapper to prevent EADDRESSINUSE conflict with tests
console.log('Find all the things at ' + conf.url);
module.exports = app;