-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
36 lines (30 loc) · 907 Bytes
/
index.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
/* no-global-assign Promise */
const mongoose = require('mongoose')
// config should be consted before importing any other file
const config = require('./config/config')
const app = require('./config/express')
// make bluebird default Promise
Promise = require('bluebird') // eslint-disable-line no-global-assign
// plugin bluebird promise in mongoose
mongoose.Promise = global.Promise
// connect to mongo db
const mongoUri = config.mongo.host
mongoose.connect(mongoUri, {
useMongoClient: true,
server: {
socketOptions: {
keepAlive: 1
}
}
})
mongoose.connection.on('error', () => {
throw new Error(`unable to connect to database: ${mongoUri}`)
})
// module.parent check is required to support mocha watch
if (!module.parent) {
// listen on port config.port
app.listen(config.port, () => {
console.info(`server started on port ${config.port}`)
})
}
module.exports = app