-
Notifications
You must be signed in to change notification settings - Fork 4
/
app.js
39 lines (28 loc) · 955 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
global._ = require('lodash');
var express = require('express');
var config = require('./config/config');
var glob = require('glob');
var mongoose = require('mongoose');
mongoose.Promise = global.Promise;
var models = glob.sync(config.root + '/app/models/*.js');
models.forEach(function (model) {
require(model);
});
var app = express();
module.exports = require('./config/express')(app, config);
/* If we are running in IIS, we did not start via "node ./bin/www".
Therefore, start listening here. */
if (process.env.hasOwnProperty('IISNODE_VERSION')) {
require('http');
mongoose.connect(config.db);
var db = mongoose.connection;
db.once('open', function () {
console.log('Connected to ' + config.db);
});
db.on('error', function () {
throw new Error('unable to connect to database at ' + config.db);
});
app.listen(config.port, function () {
console.log('Express server listening on port ' + config.port);
});
}