-
Notifications
You must be signed in to change notification settings - Fork 224
/
main.js
34 lines (25 loc) · 808 Bytes
/
main.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
'use strict';
var fs = require('fs-extra');
var path = require('path');
var http = require('http');
var express = require('express');
var mongoose = require('mongoose');
var bodyParser = require('body-parser');
var errorHandler = require('errorhandler');
var config = require('./config');
var logger = require('./logger');
var api = require('./api');
// Connect to the database
mongoose.connect(config.mongo.uri, config.mongo.options);
var app = express();
// Setup server
var server = http.createServer(app);
app.use(bodyParser.json());
app.use(errorHandler());
app.use('/', api);
// Start server
server.listen(config.port, config.ip, function () {
logger.info('Express server listening on ' + config.port + ' in ' + app.get('env') + ' mode\n');
});
// Expose application
module.exports = app;